As the downturn has ground on, some of the worst-hit cities and states have resorted to fiscal sleight of hand to stay afloat, helping them close yawning budget gaps each year, but often at great future cost.

Few workers with neglected 401(k) retirement accounts would risk taking out second mortgages to invest in stocks, gambling that the investment gains would be enough to build bigger nest eggs and repay the loans.

But that is just what Illinois, which has been failing to make the required annual payments to its pension funds for years, is doing. It borrowed $10 billion in 2003 and used the money to invest in its pension funds. The recession sent their investment returns below their target, but the state must repay the bonds, with interest. The solution? Illinois sold an additional $3.5 billion worth of pension bonds this year and is planning to borrow $3.7 billion more for its pension funds.

It is the long-term problems of a handful of states, including California, Illinois, New Jersey and New York, that financial analysts worry about most, fearing that their problems might precipitate a crisis that could hurt other states by driving up their borrowing costs.

But it is the short-term budget woes that nearly all states are facing that are preoccupying elected officials.

Illinois is not the only state behind on its bills. Many states, including New York, have delayed payments to vendors and local governments because they had too little cash on hand to make them. California paid vendors with i.o.u.’s last year. A handful of other states, worried about their cash flow, delayed paying tax refunds last spring.

Now, just as the downturn has driven up demand for state assistance, many states are cutting back.

The demand for food stamps has been rising significantly in Idaho, but tight budgets led the state to close nearly a third of the field offices of the state’s Department of Health and Welfare, which take applications for them. As states have cut aid to cities, many have resorted to previously unthinkable cuts, laying off police officers and closing firehouses.