FRANKFORT, Ky. — The Kentucky Supreme Court on Thursday struck down a law that made changes to the state's struggling public pension system eight months after it prompted thousands of teachers to protest, closing schools across the state.

Public pension systems across the country are in trouble as workers live longer and states grapple to make up investment losses from the Great Recession. But Kentucky's pension systems are among the worst funded in the country. The state is at least $38 billion short of the money it needs to pay benefits over the next three decades.

In April, Republican Gov. Matt Bevin signed a law that moved all new teacher hires into a hybrid pension plan. The law also restricted how teachers used sick days to calculate their retirement benefits and changed how the state pays off its pension debt.

Facing a tight deadline, state lawmakers introduced and passed the bill in one day near the end of the 2018 legislative session. The bill moved so quickly that a copy was not available for the public to read until the day after lawmakers had voted on it.

Teachers were outraged, thousands marched on the Capitol and schools in more than 30 districts closed. Democratic Attorney General Andy Beshear sued, arguing the legislature violated the state Constitution by not voting on the proposal three times over three separate days. Bevin argued lawmakers did not need to do that because they had substituted the bill for an unrelated one that already had the required votes.

Thursday, the state's highest court sided with Beshear. It ruled that lawmakers cannot take a bill close to final passage and replace it with an unrelated bill without voting on it three times over three separate days as the Constitution requires.

The ruling could have political consequences. Bevin is up for re-election in 2019, and Beshear is one of the Democratic candidates vying to replace him. The two men have clashed in court multiple times since 2015.

Thousands of teachers gather during a rally for education funding and changes to their pension system at the state Capitol in Frankfort, Kentucky, on April 2, 2018. Alex Slitz / Lexington Herald-Leader via AP file

"I guarantee you that if they strike down (the pension law), you can kiss your pensions goodbye," Bevin said during a public forum last week in Maysville, according to the Courier Journal.

Beshear dismissed Bevin's criticism as "fear mongering."

"It has absolutely no basis in fact, it's simply a governor trying to pressure what's supposed to be a co-equal branch of government into doing what he wants," Beshear told reporters earlier this week.

It's unclear how the legislature will respond. Lawmakers are scheduled to reconvene in January, and they could opt to pass the bill again without using the legislative maneuver the court ruled unconstitutional.

Democrats had hoped the backlash on the pension vote would give their candidates a boost in the November elections. But on Election Day, more lawmakers who opposed the pension bill lost than did those who supported it. Democrats made modest gains in the House, but Republicans maintained substantial majorities in both chambers.

Meanwhile, the Kentucky Teachers' Retirement System is improving. Independent consultants said last month that the system has more money and less unfunded debt since the legislature decided to fully fund the system's budget request. Kentucky Teachers' Retirement System Executive Secretary Gary Harbin told reporters the fate of the pension bill would have little effect on the system's future solvency.