The Pennsylvania supreme court on Monday struck down the boundaries of the state’s 18 congressional districts, granting a major victory to plaintiffs who contended that they were unconstitutionally gerrymandered to benefit Republicans.

Republicans who controlled the legislature and governor’s office following the 2010 census broke decades of geographical precedent when redrawing the map, producing contorted shapes including one that critics said resembled “Goofy kicking Donald Duck”.

They shifted whole counties and cities into different districts in an effort to protect a Republican advantage in the congressional delegation. They succeeded, securing 13 of 18 seats in a state where registered Democrats outnumber Republicans five to four.

The Democratic-controlled court said the boundaries “clearly, plainly and palpably” violated the state’s constitution, and blocked the map from remaining in effect for the 2018 elections. The deadline to file paperwork to run in primaries for the seats is 6 March.

The court order gives the Republican-controlled state legislature until 9 February to pass a replacement and the Democratic governor, Tom Wolf, until 15 February to submit that replacement to the court.

Otherwise, the justices say they will adopt a plan in an effort to keep the state’s 15 May primary election on track.

The decision means 14 sitting members of Congress and dozens more people are running or considering running in districts they may no longer live in.

The 13 March special election in a vacant south-western Pennsylvania seat was unaffected by the order, the justices said.

“We won the whole thing,” said David Gersch of the Arnold & Porter Kaye Scholer law firm in Washington DC, which is helping represent the group of registered Democrats who filed the lawsuit last June.

The US supreme court also is weighing whether redistricting can be so partisan that it violates the US constitution, in cases from Maryland and Wisconsin. The court has never struck down an electoral map as a partisan gerrymander.

A federal court recently found North Carolina’s 2016 redistricting plan to be a violation of the constitution’s equal protection clause and an infringement on the free speech of voters who cannot meaningfully cast a ballot if the outcome is all but predetermined.

That court ordered the legislature to come up with new, fairer maps within two weeks and said if they did not, a court-appointed expert would redraw the maps for them.