RALEIGH — A North Carolina judicial panel rejected state legislative district maps Tuesday, saying legislators took extreme advantage in drawing voting districts to help elect a maximum number of Republican lawmakers. The judges gave lawmakers two weeks to try again.

The three-judge panel of state trial judges unanimously ruled that courts can step in to decide when partisan advantage goes so far it diminishes democracy. Their ruling comes after the U.S. Supreme Court ruled in June in a separate case involving North Carolina's congressional map that it's not the job of federal courts to decide if boundaries are politically unfair — though state courts could consider whether gerrymandering stands up under state laws and constitutions.

The state judges found that the way the majority-Republican General Assembly redrew legislative district maps in 2017 violated the rights of Democratic voters under the state constitution's equal protection and freedom of assembly clauses.

"Partisan intent predominated over all other redistricting criteria resulting in extreme partisan gerrymandered legislative maps," the judges wrote. "The effect of these carefully crafted partisan maps is that, in all but the most unusual election scenarios, the Republican Party will control a majority of both chambers of the General Assembly. In other words, the court finds that in many election environments, it is the carefully crafted maps, and not the will of the voters, that dictate the election outcomes in a significant number of legislative districts and, ultimately, the majority control of the General Assembly."

Rep. David Lewis, a chief defendant in the case, declined to comment. Senate leader Phil Berger said senators would follow the court's instructions and adopt "a nonpartisan map," but his prepared statement didn't explicitly rule out a possible appeal.

The court gave lawmakers until Sept. 18 to again redraw maps to be used in next year's elections. The judges said they would appoint an outside referee to advise them in next steps, including drawing maps if lawmakers miss their Sept. 18 deadline.

The judges also raised the possibility they would postpone the state's March primary for legislature or other offices if they feel it's necessary.

Redistricting is the process of redrawing voting districts for state legislatures and Congress after every decennial census. Gerrymandering describes when the redistricting is slanted to give one political party a majority in as many districts as possible. North Carolina's legislative districts were redrawn in 2017 after a federal court determined they were an illegal gerrymander that sought to weaken the voting strength of minority voters.

But the group Common Cause and more than 30 registered Democratic voters sued, saying the 2017 districts were still so gerrymandered they unconstitutionally insulated Republicans from changes in voting behavior.

Lawyers for Republican state legislators argued there was no clear way for judges to know what kinds of map-making are unacceptable, since "redistricting is political because of what it is, not because of who does it." Any complaints about how districts were drawn would vanish if Democrats could lead some GOP voters to change their minds and voted with them, GOP lawyers said.

If state courts ultimately rule in favor of Democrats, they could order new district maps for next year's legislative elections. Lawmakers winning those elections will draw up maps after the 2020 census to last for the following decade, again influencing political power in the country's ninth-largest state.

The lawsuit contended that most of the 170 House and Senate districts drawn in 2017 violated the plaintiffs' free speech and association protections under the state constitution. It also said the boundaries violated a constitutional provision stating "all elections shall be free," because the maps are rigged to predetermine electoral outcomes and virtually ensure Republican control of the legislature.

The three-judge panel agreed Tuesday that part of the state constitution was violated.

The ruling appears to meet the request of plaintiffs by ordering that nearly half of state House districts and 21 of 50 Senate maps redrawn quickly, Common Cause NC spokesman Bryan Warner said.

The judges also imposed rules on a new round of redistricting. The new mapmaking must start from scratch, all map-drawing must occur at public hearings with computer screens visible to everyone and any consultants hired by lawmakers must be approved by the court.

Evidence introduced during the two-week trial in July included computer records created by Tom Hofeller, a now-dead GOP redistricting guru who helped draw the 2017 legislative maps. Those files, collected by Hofeller's estranged daughter after his death and shared with Common Cause, showed that Republican advantage was the overall objective of the latest redistricting.

Some of Hofeller's files were also used in separate litigation in New York challenging a plan by President Donald Trump's administration to include a citizenship question on the 2020 U.S. census.

The North Carolina lawsuit marks at least the eighth legal action challenging state election district maps since the current round of redistricting began in 2011. The lawsuits resulted in redrawing congressional lines in 2016 and legislative districts in 2017 — both to address racial bias.