WASHINGTON — The Supreme Court is upholding Texas’ use of electoral districts that a lower court struck down as racially discriminatory.

The justices ruled 5-4 Monday in an unusual case involving congressional and state legislative districts that had first been adopted by the lower court on an interim basis, then approved by the Texas Legislature.

In 2017, the same judges who approved the interim maps in 2012 agreed with the challengers that the maps were the product of intentional discrimination.

But Justice Samuel Alito said for the court’s conservative majority that the lower court made a mistake by striking down two congressional and seven state house districts. The high court struck down one safe Democratic House district in Fort Worth because the state relied too heavily on race when it increased the district’s Latino population.

“We now hold that the three-judge court committed a fundamental legal error,” Alito wrote. The lower court ignored evidence showing that the legislature adopted districting plans in 2013 primarily to try to end the litigation over the districts, Alito said.

The court’s liberal justices dissented.

“The court today does great damage to that right of equal opportunity,” Justice Sonia Sotomayor wrote. She said her colleagues had blinded themselves “to the overwhelming factual record below. It does all of this to allow Texas to use electoral maps that, in design and effect, burden the rights of minority voters.”

Texas’ congressional and legislative districting plans have been embroiled in court action for years, beginning in 2011.

After the state’s original maps were tossed out as probably unconstitutional, a three-judge federal court produced interim districting plans that were used in the 2012 elections.

In 2013, Republicans who control the state government rushed to permanently adopt those maps to use for the rest of the decade, until a new round of redistricting after the 2020 census. But opponents criticized the adopted maps as a quick fix that didn’t purge all districts of the impermissible use of race.

The three-judge court concluded that some districts were almost identical to the earlier versions and were rife with racial bias.

The ruling is a blow for Democrats who are outnumbered nearly 2-1 in the Texas Legislature and are unlikely to pick up many seats in November, even after seeing record primary turnout in March.

“This is a huge win for the Constitution, Texas, and the democratic process. Once again, Texans have the power to govern themselves,” Republican Texas Attorney General Ken Paxton said.

Associated Press writer Paul Weber in Austin, Texas, contributed to this report.

READ MORE: Supreme Court won’t hear North Carolina districting dispute