Federal Reserve Chairman Ben Bernanke sounded a cautiously upbeat note on the U.S. economy on Wednesday but warned that corralling government debt was vital to ensuring the nation's long-term health.

In testimony to Congress, Bernanke sounded more confident that the U.S. recession would end this year than he had just one month ago, and he said the risk of a dangerous downward spiral in prices had receded.

Delivering a message that appeared aimed at soothing jittery financial markets and reassuring foreign investors that the United States would get a grip on its budget once the economic crisis has passed, Bernanke said rising deficits posed a significant long-term threat.

Maintaining the confidence of the financial markets requires that we, as a nation, begin planning now for the restoration of fiscal balance, Bernanke told the House of Representatives' Budget Committee.

Unless we demonstrate a strong commitment to fiscal sustainability in the longer term, we will have neither financial stability nor healthy economic growth.

He said rising debt was contributing to a jump in longer-term interest rates. However, he gave no clue as to whether the U.S. central bank would step up its purchases of government and mortgage-related debt to keep rates low, something investors have been watching for.

Financial markets largely shrugged off Bernanke's testimony, with weaker-than-expected economic data driving prices for U.S. stocks down and Treasury debt up.

U.S. President Barack Obama has said big deficits are a necessary evil while the economy is suffering from the credit and housing market busts, and that once the crisis has passed, the focus will shift to shoring up the fiscal position.

That is a critical issue for countries such as China that hold hundreds of billions of dollars in U.S. government debt. If the United States is unable to control its long-term deficits, it could weaken the dollar and drive up inflation, hurting the value of those dollar-denominated assets.

U.S. Treasury Secretary Timothy Geithner, on his first visit to China as Treasury chief this week, sought to reassure Beijing that the United States was committed to living within its means.

Sources in China, Japan, India and South Korea told Reuters central banks in those countries, which together control about half of the world's foreign exchange reserves, would keep buying U.S. government debt even if the United States' sovereign credit rating were cut.

'FAINT WARNING BELLS'

While offering a rosier assessment of the economy, Bernanke acknowledged that even after a recovery gets under way, growth would likely remain below its potential for a while.

We now are on a process of slow and gradual repair, both in the financial system and the economy, he said. We averted, I think, a very, very serious calamity.

He said financial markets had improved, thanks in part to the Fed's efforts to restore lending, but he also took note of the recent spike in yields on longer-term Treasury debt and fixed-rate mortgages, which some analysts worry could choke off an economic recovery.

These increases appear to reflect concerns about large federal deficits but also other causes, including greater optimism about the economic outlook, a reversal of flight-to-quality flows, and technical factors related to the hedging of mortgage holdings, Bernanke said.

The Fed has committed to buy up to $300 billion in Treasury debt and $1.45 trillion in mortgage-related debt, but some economists have called for even more purchases to counteract the rise in interest rates.

Representative Paul Ryan, the top Republican on the panel, said the rising bond yields were telling us that there is no free lunch, and cautioned that the combination of huge debt issuance and central bank buying could be dangerous.

The Treasury is issuing debt and the central bank is buying it, Ryan told Bernanke. It gives the alarming impression that the U.S. one day might begin to meet its financial obligations by simply printing money.

That could trigger inflation, and Ryan said there were already faint warning bells of inflation going off as evidenced by a weaker dollar and rise in gold prices.

Bernanke said he didn't think inflation was currently a concern, even as he said deflation risks had lessened. He said even with a recent jump in the price of oil and other commodities, cost pressures generally remain subdued.

As a consequence, inflation is likely to move down some over the next year relative to its pace in 2008. That said, improving economic conditions and stable inflation expectations should limit further declines in inflation, he said.

(Editing by Andrea Ricci)