WASHINGTON — The Supreme Court ruled Monday that North Carolina’s Republican-controlled legislature unlawfully relied on race when drawing two of the state’s congressional districts.

The decision continued a trend at the court, where justices have found that racial considerations improperly predominated in redistricting decisions by Republican-led legislatures in Virginia, Alabama and North Carolina. Some involved congressional districts, others legislative districts.

The states had contended their efforts were partisan attempts to protect their majorities, which the Supreme Court in the past has allowed, rather than attempts to diminish the impact of minority voters, which is forbidden.

But the justices declared North Carolina had relied too heavily on race in their efforts to “reshuffle,” in the words of Justice Elena Kagan, voters from one district to another. They were unanimous in rejecting one of the districts, and split 5 to 3 on the other.

In the split decision, Justice Clarence Thomas joined the liberal justices in saying race improperly predominated the drawing of the district. New Justice Neil Gorsuch was not on the court when the case was heard and took no part in the decision.

Redistricting is part of a bare-knuckled fight in North Carolina, where Democrats and Republicans uneasily share political power. Last week, the Supreme Court said it would not review a lower court’s ruling that a sweeping 2013 rewrite of the state’s voting laws was an unconstitutional attempt to diminish the power of African-American voters. The state’s Republican legislative leadership had asked the Supreme Court to get involved, but the Democratic governor and attorney general said they did not want to defend the law.

In the case involving the congressional districts, a lower court had found them improperly drawn, and in 2016 elections were held in redrawn districts. Republicans maintained control of 10 of 13 districts.

The charge from challengers was that North Carolina legislators had packed minority voters into a few districts in order to dilute their influence in other races. The state contended it was required to consider race in drawing the districts, but their overall effect was to preserve Republican control.

Chief Justice John Roberts and Justices Anthony Kennedy and Samuel Alito were the dissenters in the decision. Alito wrote that drawing the districts is “readily explained by political considerations.”