Nearly two years before President Obama and Congress were warned that the United States could lose its top-of-the-line credit rating, their counterparts in London received the same message.

British politicians responded to the admonition from Standard & Poor’s with deep spending cuts and tax increases. In the following year, British economic growth slowed dramatically and the streets filled with demonstrators opposing the cuts.

The experience could be instructive as U.S. officials weigh what to do about the nation’s soaring debt.

On Monday, S&P changed its outlook on the United States from “stable” to “negative.” The ratings agency said the country could lose its coveted AAA credit rating if it didn’t work quickly to curb its fast-growing national debt.

In May 2009, S&P took the same action with Britain.

Within a year, a new Conservative Party-led coalition in Parliament put in place dramatic measures to cut government spending by 25 percent, raise the national sales tax to 20 percent from 17.5 percent and reduce the annual budget deficit. The prized National Health Service was saved from cuts.

S&P rewarded Britain, saying the country was no longer at risk of a downgrade and upgrading its rating to “stable.”

But the austerity plan came with significant costs.

Economic growth, which had been tepid in the wake of the global recession, slowed dramatically. In fact, in the final three months of 2010, growth turned negative, and the British economy shrank by half a percentage point.

Massive demonstrations ensued in protest of budget cuts that could cost hundreds of thousands of workers their jobs, cut welfare payments and force people to postpone retirement.

But there were also advantages.

The global capital markets kept their faith in Britain — crucial for a country that for the near future will need to borrow heavily at cheap rates to finance government operations.

As concerns about the massive British debt took center stage in 2009, interest rates on the country’s 10-year bonds had been rapidly increasing, rising to 4.2 percent from 3 percent.

It was a sign that the country’s creditors were beginning to get nervous that the nation’s debt was becoming unsustainable.

After the new Conservative-led coalition passed the austerity plan, interest rates promptly dropped, falling below 3 percent. Today they’re about 3.5 percent.

Jacob Funk Kirkegaard, a research fellow at the Peterson Institute for International Economics, said it was important for Britain to take the steps, even if they proved politically detrimental.

“At the time you avoided what could be quite a destabilizing scenario. If you had not adopted that kind of austerity plan, the U.K. would not have been put back on a solid path of stability,” Kirkegaard said.

It is not as clear whether the United States faces the same urgency to pursue significant cuts to reduce the deficit.

“You don’t have to have extreme austerity right now to come up with a plan that is long term,” said Steven Hess, chief credit officer of Moody’s ratings agency. “It’s the long term trajectory that’s important.”

But analysts at S&P, a Moody’s rival, suggest there is greater urgency. Credit analyst Nikola G. Swann said that to preserve its credit rating, the United States needs to be clearly implementing a plan to reduce the debt by 2013.

The financial markets have so far shrugged off concerns about the U.S. debt. Interest rates on U.S. government bonds have stayed low and even declined Monday when S&P issued its warning.

Economists say there are reasons to believe that capital markets will continue to provide cheap money to the United States. The dollar is the dominant global currency, and the Treasury bond is the most widely traded asset, considered a risk-free place to store money for countries, banks and investors the world over.

On the other hand, economists say the centrality of the Treasury bond in the global economy raises the stakes if a crisis of confidence were to envelop the United States.

While Japan was able to withstand an outright downgrade in 2002, it is difficult to guess at the cascading effects if that were to happen to the world’s most important economy.