North Carolina‘s Republican-drawn congressional map is illegally gerrymandered and must be redrawn as quickly as possible, federal judges have ruled.

In a 191-page ruling, a three-judge federal panel said the state legislator responsible for the map had said he drew it to give Republican candidates an advantage.

It said David Lewis, the Republican House redistricting chief, attempted to justify the criteria in a 2016 debate by saying: “I think electing Republicans is better than electing Democrats. So I drew this map to help foster what I think is better for the country.”

The ruling is the first time a federal court has blocked a congressional map because of partisan gerrymandering.

However, it is the second time in a decade the Republican-controlled state General Assembly’s congressional boundaries have been thrown out by federal judges.

In 2016, another panel struck down two majority black districts on grounds they were racially discriminatory.

North Carolina's six black women police chiefs: We are proud to have smashed the glass ceiling

The latest lawsuit, which was filed by election advocacy groups and Democrats, argued Republican legislators went too far when they followed criteria designed to retain the party’s 10-3 majority in the state delegation.

All three judges agreed the “invidious partisanship” in the plan violated the Constitution’s equal protection provision.

“We find that the General Assembly drew and enacted the 2016 plan with intent to subordinate the interests of non-Republican voters and entrench Republican control of North Carolina’s congressional delegation,” a US Circuit Court Judge, Jim Wynn, wrote in the majority opinion.

The evidence shows the “plan achieved the General Assembly’s discriminatory partisan objective,” Judge Wynn added.

The judges ordered the General Assembly to approve another set of districts by 24 January. Congressional elections are scheduled across the United States for November.

North Carolina clashes with US over public restroom law Show all 14 1 /14 North Carolina clashes with US over public restroom law North Carolina clashes with US over public restroom law Gender neutral signs are posted in the 21C Museum Hotel public restrooms on May 10, 2016 in Durham, North Carolina. Sara D. Davis/Getty North Carolina clashes with US over public restroom law The "We Are Not This" slogan is posted at the entrances to Bull McCabes Irish Pub on May 10, 2016 in Durham, North Carolina. Sara D. Davis/Getty North Carolina clashes with US over public restroom law Museum manager Jeff Bell adheres informative backing to gender neutral signs in the 21C Museum Hotel public restrooms on May 10, 2016 in Durham, North Carolina. Sara D. Davis/Getty North Carolina clashes with US over public restroom law A unisex sign and the "We Are Not This" slogan are outside a bathroom at Bull McCabes Irish Pub on May 10, 2016 in Durham, North Carolina. Sara D. Davis/Getty North Carolina clashes with US over public restroom law Gender neutral signs are posted in the 21C Museum Hotel public restrooms on May 10, 2016 in Durham, North Carolina. Sara D. Davis/Getty North Carolina clashes with US over public restroom law A gender neutral sign is posted outside a bathrooms at Oval Park Grill on May 11, 2016 in Durham, North Carolina. Sara D. Davis/Getty North Carolina clashes with US over public restroom law Gender neutral signs are posted in the 21C Museum Hotel public restrooms on May 10, 2016 in Durham, North Carolina. Sara D. Davis/Getty North Carolina clashes with US over public restroom law Unisex signs hang outside bathrooms at Toast Paninoteca on May 10, 2016 in Durham, North Carolina. Sara D. Davis/Getty North Carolina clashes with US over public restroom law A unisex sign and the "We Are Not This" slogan are outside a bathroom at Bull McCabes Irish Pub on May 10, 2016 in Durham, North Carolina. Sara D. Davis/Getty North Carolina clashes with US over public restroom law A private women's bathroom is offered at Bull McCabes Irish Pub on May 10, 2016 in Durham, North Carolina. Sara D. Davis/Getty North Carolina clashes with US over public restroom law Gender neutral signs are posted in the 21C Museum Hotel public restrooms on May 10, 2016 in Durham, North Carolina. Sara D. Davis/Getty North Carolina clashes with US over public restroom law A unisex sign and the "We Are Not This" slogan are outside a bathroom at Bull McCabes Irish Pub on May 10, 2016 in Durham, North Carolina. Sara D. Davis/Getty North Carolina clashes with US over public restroom law A private men's bathroom is offered at Bull McCabes Irish Pub on May 10, 2016 in Durham, North Carolina. Sara D. Davis/Getty North Carolina clashes with US over public restroom law A unisex sign and the "We Are Not This" slogan are outside a bathroom at Bull McCabes Irish Pub on May 10, 2016 in Durham, North Carolina. Sara D. Davis/Getty

Ralph Hise, North Carolina’s Senate redistricting chairman, said through a spokeswoman members of Congress planned to appeal.

Dallas Woodhouse, the state’s Republican Party executive officer, said the districts “are fair and were drawn following all known rules, and existing case law,” and the ruling amounted to “partisan war on North Carolina Republican voters”.

Republicans are likely to ask the US Supreme Court to block the ruling’s enforcement until justices rule in a similar case from Wisconsin, involving unconstitutional legislative districts.

In 2016, a report by the Electoral Integrity Project said North Carolina could no longer be classified as a full-fledged democracy, likening its legal framework to Iran and Venezuela.