Two years ago, then-Rep. Pete Gallego, D-Texas, lost to a Republican challenger by a little more than 2,000 votes in a vast congressional district that stretches from San Antonio for over 800 miles of border, brush and desert to the outskirts of El Paso.

Gallego is running again, and one factor that he believes cost him the election — Texas' strict photo-identification requirements for voters — is about to change, to his benefit.

Last week the 5th U.S. Circuit Court of Appeals upheld earlier rulings that the state's voter ID law violated the Voting Rights Act by making it more difficult for minorities to vote.

The case, Veasey v. Abbott, was led by Rep. Marc Veasey, D-Texas, a Fort Worth lawmaker who is African-American. Greg Abbott, a Republican, was Texas' attorney general at the time of the suit and is now the state's governor.

Texas is one of 33 states with photo ID requirements for voters, but it has been at the forefront of setting strict, very limited ID options.

It is one of nine states that require voters to comply with a short list of identification, such as a driver's license or a passport. Advocate groups, like the nonpartisan Campaign Legal Center, say that in large rural areas it is very difficult and costly for some people to reach the Department of Public Safety for state-issued identification. Texas has been offering the ID free of charge, but a birth certificate or another supporting document is required to get it, another costly step.

Wisconsin also had its voter ID law stopped by a federal judge last week, and North Carolina has a pending case on its voter ID rules.

The Texas district judge has to come up with a remedy in time for the Nov. 8 election, with an Aug. 17 hearing set to determine what people have to show to be eligible to vote. The judge signaled her thinking by setting rules for a special legislative election Aug. 2 that enable voters without photo ID to fill out a form and present other evidence of eligibility, such as a utility bill.

"It is without question a boost for Gallego," Mark Jones, a political science professor at Rice University, said of the court's decision in an interview. He co-authored a study last year of the impact of the voter ID law on the Gallego race in the 23rd Congressional District, which is a majority Latino district with a 66 percent Hispanic voting-age population.

The 23rd District is the only competitive race of Texas' 36 seats in the U.S. House of Representatives and one that the state's Democrats, with only 11 members in Congress, are eager to recapture. Republicans are also anxious to keep the district's incumbent, Rep. Will Hurd, a rising star who is one of only two African-American GOP members in the House.

Abbott has said the law was necessary to prevent voter fraud. The state may appeal after the judge acts. The judge-imposed measures may well be temporary if the GOP-controlled Texas Legislature, which will meet in January for its biennial session, decides to write a new law.

In the 2014 election, the first cycle the law was in force, the study on the law by Rice University's Baker Institute for Public Policy and the University of Houston Hobby Center for Public Policy found that its effect in the district was to suppress voter turnout, with 10,000 to 15,000 staying home either because they were confused by the requirements or, to a smaller degree, didn't have any of the seven photo IDs on the list.

One of the people affected was Margarito Lara, an elderly Mexican-American who was born on a ranch in southern Texas but whose birth was never recorded. He did not have a driver's license and acquiring a birth certificate would have been costly, said his attorneys. Lara, who is now deceased, was unable to vote after the ID law took effect, although he had voted before. He was an intervenor in the case, represented by Texas RioGrande Legal Aid Inc.

Another affected voter was Imani Clark. As a student at Prairie View A&M University in Texas, a historically black university, Clark found she was unable to use her student ID to vote — it is not on the list of approved identification — and could not cast a ballot after the law took effect in 2013. Clark, who does not have a driver's license, is African-American, and she also intervened in the court challenge to the Texas voter-ID law.

"The most significant impact of the Texas voter photo-ID law on voter participation in CD-23 in November 2014 was to discourage turnout among registered voters who did indeed possess an approved form of photo ID," said Jones. "Gallego lost by 2,422 votes. It's very likely the voter ID law cost Gallego the election."

Gallego himself has been running hard for a year — he's put 73,000 miles on his car — and he starts every campaign event by explaining the voter ID rules. "Up until last week, we told them what ID to bring and said we'd help them get it," he said in an interview.

While he's now waiting for the Texas court's plan, Gallego, a former state legislator, is still telling voters to have ID to take to the polls. The 5th Circuit decision, he said, "makes it easier for people to vote." He anticipates that U.S. District Judge Nelva Gonzales Ramos will expand the kinds of identification voters can use.

Gallego is confident of his chances, not only because of the ruling, he said, but also because of higher turnout in presidential election years and Latinos opposed to Republican presidential nominee Donald Trump, who wants to build a wall on the border with Mexico. "People are more enthusiastic about participating in this election cycle than I've ever seen, especially among the Latino community," he said.

Hurd is defending his seat just as hard.

"We are running on our record of achievements that appeals to every voter," said Hurd campaign manager Justin Hollis, who does not plan to change his candidate's game plan. "This ruling ensures Pete Gallego will have to sell his record of zero accomplishments and doing nothing for our district while in office to the voters of Texas."