As San Francisco struggles under ballooning pension and health care costs, the city's retirees will receive unexpected cost-of-living bonuses totaling $170 million. The city's anticipated budget deficit for the coming year is $360 million.

A political battle has raged over the city's growing retirement obligations. In November, Proposition B, which would have required city workers to contribute more toward their pensions and benefits, was soundly defeated. The measure's opponents - every major elected official and energetic public-employee unions - said fears about the pension fund were overblown.

Meanwhile, the fund's fundamentals deteriorated as it gradually accounted for its huge losses in the stock market crash. It took in $414 million in contributions in 2010 but paid out $819 million.

On Jan. 4, an actuarial firm reported that the $13.1 billion San Francisco Employees' Retirement System now had an unfunded liability of $1.6 billion - triple its shortfall a year earlier. Gary A. Amelio, the system's chief since January 2010, did not respond to questions.

In spite of the shortfall, Mr. Amelio and the system's board quietly decreed in mid-December that "excess" earnings on investments in 2010 entitled retirees to an unexpected cost-of-living increase of as much as 3.5 percent this year. The special $170 million bonus is in excess of regular cost-of-living adjustments, or COLAs.

"The irony of issuing bonus payments to retirees at a time the pension fund is a billion dollars down is insane. It really is," said Jeff Adachi, San Francisco's public defender and the chief proponent of Proposition B, which he says would have saved the city $120 million this year. "It's like a bankrupt corporation paying dividends to its shareholders."

Until 2005, the city paid nothing into the pension fund because the fund had more assets than long-term liabilities and the excess investment income more than covered its expenses. During those flush years, the benefits were made increasingly generous, especially to the police and fire departments. But the system has posted investment losses for 4 of the last 10 years.

The city is required to inject cash if necessary to pay its retirees. This year, it will pay $325 million, or 13.6 percent of the total payroll of $2.4 billion. In the coming fiscal year, it will pay 18.1 percent - about $434 million. Three years from now, according to the actuarial report, the city will be paying 28.8 percent of payroll, or about $691 million.

The city's estimated budget shortfall for the coming fiscal year is $360 million. If not for its growing pension-fund contributions, the city might not face a budget crisis at all.

"No one foresaw this event, with the pension fund going down and all of a sudden a 3.5 percent raise to retired people," said Thomas J. O'Connor, head of the powerful firefighters' union and a participant in a group of city leaders and union officials trying to come up with a more palatable proposal to trim the city's employee costs.

The $170 million arose from a provision in a 2008 ballot initiative that required newly hired employees to contribute more toward benefit costs. To win support, the initiative contained a promise of increased bonus payments to retirees if the pension fund's performance exceeded its target. The pension system posted a huge loss in the 2008-9 fiscal year, so it was unsurprising that it exceeded its 7.75 percent target return the following year when the market improved.

Mr. O'Connor seems open to compromise. "In these times, with the overall health of the fund, we could see COLAs being deferred for a time until the fund is solvent again," he said. "No one imagined we'd be at this point giving a raise to people."