In a long-awaited decision, the Supreme Court agreed on Monday with a lower court ruling that found that Republican lawmakers in North Carolina drew two congressional districts with improper racial considerations in mind.

The ruling is the latest attempt by the justices to clarify the standard for what counts as unconstitutional racial gerrymandering — the push by lawmakers, especially in the South, to draw district lines based on the racial demographics of a specific area.

“The Constitution entrusts States with the job of designing congressional districts,” wrote Justice Elena Kagan in the 5-to-3 decision. “But it also imposes an important constraint: A State may not use race as the predominant factor in drawing district lines unless it has a compelling reason.”

The court concluded that the two districts ― which, following the 2010 census, were drawn to pack a higher percentage of voting-age black voters into them ― violated this principle.

Kagan was joined in her majority opinion by Justices Clarence Thomas, Ruth Bader Ginsburg, Stephen Breyer and Sonia Sotomayor.

The contested districts “have quite the history at this Court,” Kagan wrote, noting the long line of court challenges that have sought to find fault with how North Carolina draws its congressional districts.

Perhaps to illustrate the unusual shapes of Districts 1 and 12, Kagan’s opinion included an appendix with images of both, as well as one depicting all the districts in the state. She described District 12, in particular, as “snakelike.”

Supreme Court of the United States An illustration of North Carolina's congressional District 12, which the Supreme Court concluded was drawn to disadvantage black voters.

“The evidence offered at trial, including live witness testimony subject to credibility determinations, adequately supports the conclusion that race, not politics, accounted for the district’s reconfiguration,” Kagan said of District 12.

The race-versus-politics distinction in redistricting decisions matters, because lawmakers often insist that they redraw district lines for political reasons — that is, to keep winning elections and to retain their power by creating friendly districts. If it’s pure politics driving their decisions, they argue, then a map may not be unconstitutional by itself.

(In the law, that’s an unsettled question: The Supreme Court could soon agree to hear a separate Wisconsin case that addresses squarely the validity of “partisan” gerrymandering.)

But whenever a legislature relies on race to redraw district boundaries, the Supreme Court has said that judges should really take a hard look at how the legislature went about the map-drawing. And here, three federal judges concluded that race was the “predominant” factor driving North Carolina’s 2011 congressional maps, which put more black voters in Districts 1 and 12 while making neighboring districts whiter.

“The Equal Protection Clause prohibits the unjustified drawing of district lines based on race,” cautioned Kagan.

Thomas, a conservative who disfavors race-based considerations in any context, took the highly unusual step of joining the Supreme Court’s four more liberal members in ruling against North Carolina. He wrote a short concurring opinion to note that the majority “correctly applies our precedents under the Constitution and the Voting Rights Act of 1965.”

Joined by Chief Justice John Roberts and Justice Anthony Kennedy, Justice Samuel Alito wrote a partial dissent that took issue with how the majority was interpreting the Supreme Court’s own case law dealing with District 12, which the court had vindicated in a prior ruling.

“A precedent of this Court should not be treated like a disposable household item — say, a paper plate or napkin — to be used once and then tossed in the trash,” Alito wrote. In his view, the district’s “borders and racial composition are readily explained by political considerations and the effects of the legislature’s political strategy on the demographics.”

The Equal Protection Clause prohibits the unjustified drawing of district lines based on race. Justice Elena Kagan

Justice Neil Gorsuch didn’t participate in the ruling, as his colleagues had heard arguments in the dispute before he joined the court.

Former Attorney General Eric Holder, who is part of a Democratic initiative to challenge Republican-drawn districting in the courts, hailed Monday’s ruling “as a watershed moment in the fight to end racial gerrymandering.”

“Today’s ruling sends a stark message to legislatures and governors around the country: Racial gerrymandering is illegal and will be struck down in a court of law,” Holder said in a statement.

North Carolina Gov. Roy Cooper (D), who succeeded Republican Gov. Pat McCrory as the named party in the case, also praised the decision in a statement.

“North Carolina voters deserve a level playing field and fair elections, and I’m glad the Supreme Court agrees,” he said. “The North Carolina Republican legislature tried to rig Congressional elections by drawing unconstitutional districts that discriminated against African Americans, and that’s wrong.”

As if responding to Holder, the chairman of the North Carolina Republican Party said in a statement that the invalidated maps were pre-approved by his Department of Justice during the Obama years — back when the state had to submit districting plans to the federal government.

“The courts have put legislatures in an impossible situation, with their constantly changing standards,” said the state Republican Party chairman, Robin Hayes.

The Supreme Court’s ruling represents North Carolina’s second election-related setback in as many weeks. Last week, the justices declined to hear an appeal that sought to salvage a broad swath of voting restrictions.

But the state is also enveloped in a separate challenge to how the GOP-controlled General Assembly drew 28 state House and Senate districts, which a lower court also found were racially gerrymandered and may soon need to be redrawn. The high court is presently weighing the fate of those districts.