STATES ACROSS the country, already reeling from three years of austerity, face battles on two fronts now that revenue is starting to stabilize or, in some cases, recover. First, they are trying to restore funding for schools and services still suffering from budget cuts. Second, they must close staggering shortfalls in funds designed to meet the pension and health-care promises they have made to retired teachers and other public employees.

Virginia Gov. Robert F. Mc­Don­nell (R) and Maryland Gov. Martin O’Malley (D) have recognized the gravity of the second challenge. In both states, unfunded liabilities — the amount by which the state’s obligations outstrip the funds available to meet them — are many billions of dollars. In both states, it is likely to take a decade or more to put retirement funds back on firm footing. And in both, there is the risk that the stock market’s strong performance in the past two years, and the corresponding rise in the value of pension fund assets, will tempt lawmakers into thinking that the problem will somehow fix itself. It won’t.

In fact, the fix will be neither automatic nor easy. That was the lesson from the recent legislative session in Richmond, where state lawmakers balked at Mr. McDonnell’s attempt to make a meaningful dent in the state’s $17.6 billion shortfall in the pension fund.

The legislature, under pent-up pressure from an array of groups starved of funding (including state workers whose pay has barely budged in recent years), devised an anemic plan. It would direct just $108 million of new money in the coming year into the pension fund, barely a third the amount Mr. McDonnell had sought. And while all state workers will be required to resume contributions to their retirement plans after a 28-year hiatus, the amount of those contributions — 5 percent of pay — will be offset by a salary increase of the same size.

That’s hardly the type of sacrifice that will be needed. Despite the run-up in values of Virginia’s pension fund investments, the fund will only be about 61 percent funded by 2015, according to the latest projections. To his credit, Mr. McDonnell has signaled his displeasure with the legislature’s wan efforts this year as well as his determination to put the state on the path toward a real remedy starting next year. “I’m not passing this on to another governor,” he said last week.

Maryland faces what is probably an even more severe pension fund shortfall — more than $16 billion over the next 25 years, not counting billions more in unfunded health-care obligations for retired state workers. In Annapolis, Mr. O’Malley is awaiting legislative action on his wide-ranging proposal to repair the fund by 2023 with a combination of steeper contributions by employees and cutting pension and benefit obligations to future state workers.

Mr. O’Malley’s proposal has been criticized by some as insufficiently ambitious for (among other things) lacking a defined-contribution plan of the sort many private employers have adopted — and which was recommended by a state commission. Still, it would set the state in the right direction, and there are signs the legislature might give it more teeth by capping future raises for public employees, which form the basis for pension benefits.

In both states, there is more pain coming. The Wall Street rating firms have made it clear that they are taking the health of pension funds increasingly into account when determining a state’s bond rating — a critical factor for Virginia and Maryland, which both derive enormous benefits from their highly rated debt. The imperative of paying down pension obligations is likely to squeeze out other worthy priorities, including transportation, health and public safety. But states, which are under moral and legal obligation to meet their promises to retired workers, have no choice.