Hundreds of thousands of public employees and retirees stand to benefit from a major pension reform package that Gov. Mark Dayton signed into law on Thursday.

Schoolteachers, office workers, police officers and a retired parks maintenance worker were among the triumphant crowd that filled the Capitol rotunda in a ceremony for a bill signing that Dayton said would be the last piece of legislation he would sign as governor.

“I can’t tell you how many retirees and active employees have spoken with me in the last few days and told me how vitally important this is for their peace of mind, for their financial security, for their sense of being able to rely on pensions, on the promise that they’ve earned,” Dayton said.

Pension reform efforts had been going on for years, as the state stared down a future debt of $16.2 billion for pensions. Credit rating agencies warned state budget officials to get their unfunded liabilities in order, while retirees fretted about the prospect of larger cuts to their benefits.

The pension changes that passed will immediately eliminate $3.4 billion in unfunded liabilities and put Minnesota on a more stable path for the future, legislators said. The state will be contributing $141 million to pension plans over the next few years, while retirees agreed to some benefit reductions and current workers must increase their contributions to the pension funds.

The change is a shared sacrifice between employees, employers and retirees, Minnesota Management and Budget Commissioner Myron Frans said.

He excitedly told supporters of the legislation that when he sells state bonds this summer, agencies will ask whether they solved their unfunded liabilities.

“I’m going to say, ‘Yes!’ ” Frans said.

The reform would benefit more than 500,000 public employees across the state, the governor said. Theresa St. Aoro, a membership analyst at the Public Employees Retirement Association, is one of those workers.

Her job involves talking with employers to make sure workers — from snowplow drivers to probation officers — are receiving the correct amount of money in their retirement funds. She feared what legislative inaction could mean for the public employees she helps every day and for herself.

“I felt this was so important. It’s our future,” she said. “We can’t shortchange our retirees. They worked their whole lives for their retirement, and they deserve a good retirement.”

The Legislature passed the pension bill in a last-minute flurry on the final night of the session.

The House and Senate unanimously approved the legislation, and it became one of the few major changes that Dayton and state lawmakers could agree on this session.

Chris Lynch, a retired Minneapolis teacher, said he was worried lawmakers would add a “poison pill” that would kill the bill, and he was “ecstatic” that it passed.

“The partisanship disappeared on this one. They found a way to work together,” said Lynch, who said the plan was a good compromise between all the parties involved.

Republicans Sen. Julie Rosen and Rep. Tim O’Driscoll led the charge to pass the reform this year, and Thursday they stood alongside Dayton. Rosen said the legislation will not only bring security for retirees, it will make the state more financially stable.

States across the country are struggling with pension obligations.

“I just want to say to all the other states: You should stand up and watch what happened in Minnesota,” Rosen said.