The coronavirus outbreak could test the sacred nature of these programs in ways that even the crisis of 2008 did not, and ultimately force state and local governments to engage in complicated and perhaps unwinnable fights to reduce or slow the growth of benefits.

Failure to raise more money or reduce payouts could have dire consequences. Pension funds that run out of money — something that happened in Prichard, Ala., Central Falls, R.I., and Puerto Rico — could tip cities and other local governments into bankruptcy. States would be in uncharted waters because there is no bankruptcy mechanism for them; the nearest analogy is a one-off law passed by Congress for Puerto Rico, which has resulted in years of federal oversight, austerity measures and reduced debt payments to bondholders.

Public pension programs have long been endangered by a fundamental tension: With growing ranks of retirees and mature workers, they should invest conservatively, like someone on the cusp of retirement, shifting into high-quality bonds, for example, with durations timed to reflect scheduled future payments to retirees.

Instead, they often take on the kind of risk appropriate for someone with decades to go.

The accounting rules governing public pension plans have made all that risk attractive to those in charge of running and funding them: It’s simpler to put money in riskier assets and bet on rosy investment returns than to commit more taxpayer money upfront.

Economists have been saying for years that public pensions should be shifting to safer investments as their members age. But Andrew Biggs, an economist at the American Enterprise Institute who specializes in retirement financial issues, said public pension systems hadn’t listened.

In fact, they’ve taken on even more risk.

As of 2018, state pension funds had on average invested 74 percent of their money in what Mr. Biggs called risky assets, including stocks, private equities, hedge funds and commodities. That was up from 69 percent in 2010, after the 2008 shock, and from 61 percent in 2001, when economists first began challenging the way public pensions operate.

“This was completely predictable,” Mr. Biggs said. “They are holding tons of equities when they’ve also got tons of retirees.”