FRANKFORT, Ky. — The Kentucky Supreme Court on Thursday struck down a law that made changes to one of the country's worst-funded public pension systems, a victory for teachers who closed schools across the state in protest earlier this year.

Thousands of teachers filled the state Capitol in the spring, chanting and carrying signs as they sought to pressure lawmakers to reject a proposal that would have cut their benefits.

Lawmakers passed a bill anyway. But the final version had little effect on current teachers and public workers. Still, teachers were outraged because lawmakers used a legislative maneuver to pass the bill so quickly it was not available for the public to read it until the day after the vote. Thursday, the state's highest court ruled that maneuver was unconstitutional, making the law invalid.

"I do feel vindicated. I'm proud of what we did," said Jessica Page, an art teacher at Kathryn Winn Primary in Carrolton, Kentucky. "I also do respect the governor and respect the fact that we do need some type of pension reform. I think it needs to be fair and I think it needs to be out in the open."

Democratic Attorney General Andy Beshear, who filed the lawsuit that led to Thursday's ruling, called it "a landmark win for all of our public servants." But Republican Gov. Matt Bevin called it "an unprecedented power grab by activist judges."

"This will destroy the financial condition of Kentucky," Bevin said, a claim Beshear dismissed as "fear mongering."

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 considered the worst of the worst, with the state at least $38 billion short of the money it needs to pay benefits over the next three decades.

The shortfall has required state lawmakers to divert billions of dollars in state money to the pension system, making it harder to pay for things like education and health care.

In April, 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. Beshear sued. On Thursday, he won.

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.

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.

Republican leaders in the state House of Representatives released a statement Thursday saying they were committed "to enact a solution" for the pension system. But they noted the legislature has been passing bills like this for decades and warned Thursday's ruling could lead to a mountain of lawsuits.

The justices considered that argument, and rejected it. Justice Daniel Venters wrote any lawsuits that might have been filed "in timely fashion to challenge the enactment of now well-established laws are beyond the purview of this opinion."

"We are not persuaded from the record here that such a potential parade of horrors awaits," he wrote.

Democrats had hoped the backlash on the pension bill 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 picked up two seats in the House, but Republicans maintained substantial majorities in both chambers.

The Kentucky Democratic Party viewed Thursday's ruling as a momentum swing, saying it will work to make Bevin "a one-term governor." But Bevin and Beshear bristled at questions of how the ruling will affect the 2019 elections, both saying this was not about politics.

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 law would have little effect on the system's future solvency.