LOUISVILLE, Ky. (AP) — Kentucky's new public pension overhaul law was struck down Wednesday in a setback for the state's Republican leaders on an issue that angered thousands of teachers who marched on the Capitol and closed schools in protest.

Franklin County Circuit Judge Phillip Shepherd, assigned to referee the state's biggest political fight, ruled that the GOP-run legislature violated the state Constitution in the accelerated way the law was enacted. Lawmakers changed the state's woefully-underfunded public retirement systems in the waning days of this year's legislative session.

The case became the latest round in a prolonged feud between Republican Gov. Matt Bevin and Democratic Attorney General Andy Beshear, who sued to block the pension measure. Beshear called the judge's ruling a "win for open, honest government" and said it voids the law in its entirety.

"Today's ruling holds the General Assembly violated Kentucky's Constitution when it turned an 11-page sewer bill into a 291-page pension bill and passed it in just six hours with no public comment or participation," Beshear told reporters

A spokeswoman for Bevin, who signed the bill, said the ruling will be appealed, adding that the ruling could cause "chaos" because other bills have cleared the legislature using the same process. State Republican Party spokesman Tres Watson said it wasn't surprising Shepherd sided with Beshear in a "politically motivated lawsuit against the General Assembly's efforts to save our state retirement system. We are confident this decision will be overturned upon appeal."

Lawmakers passed the bill earlier this year to make changes to Kentucky's public pension systems, some of the worst-funded retirement plans in the country. It also changed how current teachers can use their sick days to calculate their retirement benefits. The measure would mostly impact future hires.

The pension overhaul drew large protests, part of a national wave of demonstrations by teachers. The largest Kentucky rally drew thousands of teachers and closed dozens of school districts as teachers also called for increased education spending.

The bill that became the pension overhaul started out as an attempt to fix problems caused by abandoned private sewer systems. Lawmakers gutted the bill and replaced it with the pension changes. Because the bill had technically already passed the Senate, lawmakers were able to send it to the governor's desk in about six hours instead of the minimum five days the state Constitution requires to pass new legislation.

The law's detractors pointed to constitutional provisions requiring a bill to be read on three different days in each chamber. Attorneys defending the law said the "three-readings requirement" was a political question that should be left to the legislative branch.

The judge disagreed. Shepherd said the requirement was enacted by the constitution's framers "to ensure that legislators and the public know the substance and the content of the bills they vote on. It is a constitutional mandate — not an internal procedural rule of the General Assembly."

Shepherd also said the bill appropriates money and thus needed the support of a majority of House members to pass. The measure was approved with 49 votes, two shy of a constitutional majority in the 100-member chamber.

Bevin spokeswoman Elizabeth Kuhn said "hundreds, if not thousands, of bills have previously been passed by the General Assembly using the exact same process."

"If all of these bills are now invalidated based on Judge Shepherd's ruling, our legal system will descend into chaos," Kuhn said in a statement.

But Shepherd said in his ruling that other laws were not at issue in this case.

Shepherd did not rule on whether the law violated the state's "inviolable contract" with teachers and other public workers.

The pension issue became a political firestorm for Republican lawmakers who consolidated control of Kentucky's legislature after sweeping the 2016 election.

The pension measure required all new teacher hires be put into a hybrid pension system, and changed how current teachers could use their sick days to calculate their retirement benefits.

The case turned personal when Bevin went on talk radio and called Shepherd an "incompetent hack." The judge angered Bevin when he ruled the governor's lawyers could not take deposition testimony from staff in the Attorney General's Office and the Kentucky Education Association, the state's largest teachers' union.

Bevin's lawyers asked Shepherd to recuse himself, arguing he could not rule fairly because he's a member of one of Kentucky's retirement systems. Shepherd refused to step aside.