The federal government posted a $318.62 billion deficit for its 2005 fiscal year, down sharply from last year's record mainly because of an unexpected surge in tax revenue.

Administration officials said the narrower budget gap for the year ended Sept. 30 was vindication of President Bush's economic policies, including his tax cuts. But the costs of hurricane relief and the wars in Iraq and Afghanistan are almost certain to widen the deficit in the current fiscal year, and analysts warned that the good news for 2005 does not diminish their worries about enormous budget problems when the baby-boom generation begins to retire after Bush leaves office.

The 2005 deficit was the third-largest ever. But it was not only markedly smaller than the record $412.85 billion for 2004, it was also well below the forecasts for the year issued in February. As a proportion of the economy -- it equaled about 2.6 percent of gross domestic product -- the deficit was within bounds that most economists consider manageable, and far from the levels of the 1980s, when the deficit reached nearly 6 percent of GDP.

"Lower taxes and pro-growth economic policies have created millions of jobs and a growing economy that has swelled tax revenues over the last year," Treasury Secretary John W. Snow said in a written statement. "While deficits are never welcome, the fact that we finished FY 2005 with a much lower-than-expected deficit is encouraging news."

Democrats said "lower-than-expected" did not apply if the basis for comparison was the fiscal outlook at the time Bush took office.

Noting that the Bush team initially forecast a $269 billion surplus for 2005, Rep. John M. Spratt Jr. (D-S.C.), ranking minority member of the House Budget Committee, said the final figure was "$588 billion worse than the Bush administration projected when it sent up its first budget in 2001."

Although federal spending rose 7.9 percent above fiscal 2004, to $2.47 trillion, tax receipts rose 14.6 percent, to $2.15 trillion. The year-to-year increase in revenue was the most in more than 20 years, and, perhaps most gratifying for the administration, receipts ended up $101 billion higher than projected in February.

Those figures confirmed the improvement in the near-term budget picture that began to emerge in July, when government and independent economists realized that the deficit would shrink in 2005 for the first time in Bush's presidency. The principal reason for the turnaround was that corporate tax receipts were well above what was expected, a phenomenon that budget experts won't be able to explain fully until they are able to examine 2005 tax returns a couple of years from now.

Many economists said the improvement in tax revenue is likely to be ephemeral. Furthermore, since most of the $62 billion in emergency spending for hurricanes Katrina and Rita will be disbursed in the current fiscal year, the deficit is likely to rise anew, perhaps back to the $400-billion-plus range, some forecasters say.

Even at that level, the budget gap as a proportion of total output would be well below levels that economists view as worrisome, and the deficit may well stay in the range of 2 to 2.5 percent of GDP until 2008, according to many projections.

"But the paramount fact is that everything beyond that looks far more troubling," said Douglas J. Holtz-Eakin, the director of the Congressional Budget Office and a former Bush aide. "And nothing that has happened in the past year changes that."

As the baby boomers retire, not only will Social Security outlays rise steeply, but Medicare and Medicaid spending also will soar to staggering levels unless policy is changed, Holtz-Eakin said. Federal spending on the two health care programs will rise from about 4 percent of GDP now to 20 percent of GDP by 2050, based on current cost trends and demographic projections.

"So it's hard to get excited about a $318 billion deficit when you're looking at a projection suggesting that 318 will turn into 1,318 if you don't do something," Holtz-Eakin said. "At the moment, the deficit is something this economy can handle. It's the going forward part that worries me."