In a major blow to Republicans who control the Legislature in one of the nation’s most bitterly divided states, a state court panel threw out North Carolina’s state legislative maps as an unconstitutional partisan gerrymander and ordered lawmakers to draw up new ones in two weeks.

The ruling on Tuesday by a three-judge panel in Raleigh had the potential to bring to a decisive end a yearslong battle over gerrymandering in a critical swing state and indicated that state courts could act to rein in patently partisan electoral maps after the United States Supreme Court ruled in June, by a 5-to-4 margin, that federal courts could not.

The Republican leader of the State Senate, Phil Berger, cast the decision as part of a national Democratic strategy to overturn Republican rule via the courts, but said the Legislature would not appeal the ruling. The North Carolina Supreme Court, which would hear any appeal, has six Democratic justices and one Republican.

“It contradicts the Constitution and binding legal precedent, but we intend to respect the court’s decision and finally put this divisive battle behind us,” Mr. Berger said in a statement. “It’s time to move on.”