RIVERSIDE, Calif. (AP) — The city of San Bernardino has agreed to pay the California Public Employees’ Retirement System all that it owes in bankruptcy proceedings, the second city in recent months to opt to keep pensions intact despite a court ruling that says the benefits can be slashed if the employer is bankrupt.

A filing Monday in U.S. Bankruptcy Court in Riverside spelled out a deal in which the city will make up $13.5 million in payments it missed since it declared bankruptcy in 24 equal installments, plus interest and fees, over the next two years, starting in July, the San Bernardino Sun reported Wednesday (http://bit.ly/11u04wk ).

The city and CalPERS announced a tentative deal in June but the details were not revealed at the time. The agreement ends months of impasse between the city and CalPERS, its largest creditor. So far, the city has paid $4.5 million to CalPERS.

With the cost of public pensions rising, the Stockton and San Bernardino bankruptcies were considered important tests of whether cities would opt to curtail benefits to exit bankruptcy.

In Stockton, a creditor launched a major challenge to the city’s decision to keep paying CalPERS. San Bernardino actually withheld payments from CalPERS for several months after it filed for bankruptcy protection in 2012, racking up a past-due account of around $14 million. Some of the city’s elected leaders also talked about trying to reduce San Bernardino’s ongoing $24 million-a-year contribution to the pension fund.

At a hearing Tuesday, where creditors discussed the details of the CalPERS repayment, some bondholders indicated they opposed the plan.

The city issued bonds in 2005 to cover its pension costs and those bondholders are among the creditors who have been displeased with the length of negotiations.

“That deal is really more of a surrender,” said Vincent J. Marriott III, who represents Erste Europaische Pfandbrief- und Kommunalkreditbank AG, the Luxemburg-based holder of bonds. “At worst, the city will find there is no feasible plan that could incorporate the deal with CalPERS.”

Unions for police and firefighters said the city was taking too long to negotiate with CalPERS _ a delay that was hurting their members’ pocketbooks and their ability to budget.

Those unions met Monday’s plan to repay CalPERS with guarded optimism and downplayed the bondholder’s concerns that the deal wasn’t realistic.

“It should be no surprise to the court that the bondholders don’t want money used to pay employee pensions,” said police union attorney Ron Oliner.

At a hearing, U.S. Bankruptcy Judge Meredith Jury also gave the city six months to incorporate the deal into a final exit plan and said if it doesn’t, the case will be thrown out of court.

The city has been in bankruptcy for 28 months and has been negotiating in closed-door proceedings.

“I’d rather say this is a hard, hard deadline, and the Earth is going to have to move under San Bernardino” to get an extension, she said.