(Reuters) - A panel of federal judges on Thursday ordered Michigan’s Republican-controlled legislature to redraw nearly three dozen state and U.S. congressional districts, ruling that the existing lines illegally dilute the power of Democratic voters.

The decision gives lawmakers until Aug. 1 to approve new district maps, which would need to be signed by Democratic Governor Gretchen Whitmer.

If legislators fail to do so, or if the court finds the new district lines are similarly unconstitutional, the judges said they would draw the maps themselves. The redrawn districts would take effect in time for the 2020 elections.

The court also ordered Michigan to hold special state Senate elections next year, rather than in 2022 as scheduled, in any gerrymandered districts. The state’s 14 seats in the U.S. House of Representatives are also up for election next year, and a majority of them could have new boundaries under the court’s ruling.

The decision is likely a boon for Democrats, who in 2018 failed to win a majority of the seats in the state House of Representatives, state Senate or the state’s U.S. congressional delegation despite winning the overall popular vote in all three cases.

“Today, this court joins the growing chorus of federal courts that have, in recent years, held that partisan gerrymandering is unconstitutional,” U.S. District Judge Eric Clay, an appointee of former U.S. President Bill Clinton, wrote for a unanimous three-judge panel.

Partisan gerrymandering is the process by which one party draws legislative districts to weaken the other party’s voters. The lines are typically redrawn once a decade after the U.S. census, and in many states the party in power controls the decision-making.

In late March, the U.S. Supreme Court heard arguments on whether such gerrymandering violates the U.S. Constitution in a case stemming from the electoral maps in Maryland and North Carolina.

The Supreme Court has historically been reluctant to assert judicial oversight over what has always been a political undertaking.

The judges in the Michigan case said the gerrymandered map “gives Republicans a strong, systematic, and durable structural advantage in Michigan’s elections and decidedly discriminates against Democrats.”

The result is a violation of Democratic voters’ constitutional right under the First Amendment to freely associate, the court said.

“Federal courts must not abdicate their responsibility to protect American voters from this unconstitutional and pernicious practice that undermines our democracy,” the judges wrote.

Republican lawmakers, who intervened in the case, will appeal the ruling to the U.S. Supreme Court, state Senate Majority Leader Mike Shirkey said.

“We will prepare to comply with this most recent ruling while we await the outcome of the appeal,” Shirkey said in a statement.

The Supreme Court could choose to put the Michigan ruling on hold until it issues its own decision, which is expected by June.

The lawsuit was filed by a number of Democratic voters and by the League of Women Voters of Michigan.

Michigan was key to U.S. President Donald Trump’s victory in 2016, when he became the first Republican presidential candidate to win the state’s support in nearly 30 years. The state is likely to be a major battleground state next year, when Trump runs for a second term.