The Supreme Court for a second time sided with Texas in a years-long legal fight starting with legislative maps its statehouse drew in 2011.

In a 5-4 majority opinion written by Justice Samuel Alito, the high court reversed a lower court’s finding that that the map that Texas adopted in 2013 was adopted with a discriminatory intent. The map had been okayed by the lower court as a temporary fix for the 2012 election. But the lower court rejected the 2013 map as a permanent solution — a decision the Supreme Court largely reversed Monday, with the exception of one Texas House district.

Texas’ legislative map was first found to be racially discriminatory under the Voting Rights Act by the lower court — a three-judge panel — in 2011, but the Supreme Court ordered the lower court to narrow its remedy for fixing the map going into the 2012 elections.

The Texas legislature then rushed to adopt the map in 2013, even as the lower court said it was still assessing the effects of the map. The lower court then later ruled that Texas in doing so was continuing to act with the intent of racial discrimination — a finding that threatened to put the state back under the so-called pre-clearance regime that the Supreme Court gutted in 2013 in Shelby County v. Holder.

The Supreme Court on Monday was weighing in on appeal of the lower court’s finding that the intentional discrimination of the 2011 map had not been wiped away by the state adopting in 2013 the court-ordered map. The case was called Abbot v. Perez.

“We now hold that the three-judge court committed a fundamental legal error. It was the challengers’ burden to show that the 2013 Legislature acted with discriminatory

intent when it enacted plans that the court itself had produced,” Alito wrote. “The 2013 Legislature was not obligated to show that it had ‘cured’ the unlawful intent that the court attributed to the 2011 Legislature. Thus, the essential pillar of the three-judge court’s reasoning was critically flawed.”

Much of Alito’s opinion dealt with the procedural issue of whether Texas had appealed the case to the Supreme Court too early given that the lower court was still working on a remedy. The conservative majority rejected the argument that Texas’s appeal was premature.

Moving on to the merits of the case, Alito said that “when all the relevant evidence in the record is taken into account, it is plainly insufficient to prove that the 2013 Legislature acted in bad faith and engaged in intentional discrimination.”

In addition to reversing the lower court’s intentional discrimination decision, the Supreme Court on Monday overturned its decision that three legislative districts should be invalidated because they had a discriminatory effect, but it allowed to stand the court’s decision that a fourth district, a state House district, was an impermissible racial gerrymander.

Justice Clarence Thomas, joined by Justice Neil Gorsuch, filed a brief concurring opinion that said they did not believe the Voting Rights Act could be applied to redistricting.

Justice Sonia Sotomayor, in a dissent joined by the court’s three other liberals, bashed the majority for guaranteeing Texas “continued use of much of its discriminatory maps.”

“This disregard of both precedent and fact comes at serious costs to our democracy. It means that, after years of litigation and undeniable proof of intentional discrimination, minority voters in Texas—despite constituting a majority of the population within the State—will continue to be underrepresented in the political process,” she wrote. “Those voters must return to the polls in 2018 and 2020 with the knowledge that their ability to exercise meaningfully their right to vote has been burdened by the manipulation of district lines specifically designed to target their communities and minimize their political will. The fundamental right to vote is too precious to be disregarded in this manner.”

Read the opinion below: