The US government today announced the biggest financial bailout in the country's history as it took troubled mortgage giants Freddie Mac and Fannie Mae into temporary public ownership to save them from collapse.

The US treasury secretary, Henry Paulson, said the Federal Housing Finance Agency, hitherto the two companies' regulator, would henceforth run the companies in a state of "conservatorship" and the two chief executives would be replaced by new men.

Paulson had briefed presidential candidates Barack Obama and John McCain over the weekend about the plan. McCain gave it his immediate backing but Obama said he would reserve judgment until he saw further details, adding that determining the future of the companies would be a top priority if he won the White House.

"We have to protect taxpayers and not bail out the shareholders and management," he said.

The plan received the full backing of the Federal Reserve chairman, Ben Bernanke, and financial markets appeared likely to be cheered by the news. The move helped put a prop under one part of the financial system that had been looking particularly shaky for several months.

Rumours of the move on Friday were sufficient to push shares up on Wall Street after the London stock markets had ended a bad week by shedding another 2.25% to close at 5,240.7.

The US government was forced to announce a plan to prop up the finances of the troubled mortgage giants in July. Paulson said then that Washington would buy up shares in the two companies and underwrite their ballooning debt, which has risen to around $800bn (£452bn) each. Congress at the time approved lending unlimited amounts to the two companies or taking a stake in them if they ran into real trouble.

The two companies have lent or underwritten about $5.3 trillion of the total $12tn of outstanding mortgage debt in the United States. Freddie and Fannie have long been considered as being too big to be allowed to fail.

The collapse in the housing market and surge in mortgage defaults meant the two groups racked up a combined $14bn of losses over the past year.

Although there are increasing signs from the US that house prices are stabilising after falling for two to three years, many analysts say the housing market's problems are far from over.

"Mortgage delinquencies continue to set new records, promising more losses and future write-offs for banks and other mortgage lenders," said economists at investment bank Dresdner Kleinwort.

"The problems are spreading from the subprime sector to prime loans, particularly to mortgages with adjustable rates and optional payment features. With unemployment rising faster, cyclical problems will now compound the damage caused by falling house prices."