The government's planned takeover of Fannie Mae and Freddie Mac, expected to be announced as early as today, came together hurriedly after advisers poring over the companies' books for the Treasury Department concluded that Freddie's accounting methods had overstated its capital cushion, according to regulatory officials briefed on the matter.

The proposal to place both mortgage giants, which own or back $5.3 trillion in mortgages, into a government-run conservatorship also grew out of deep concern among foreign investors that the companies' debt might not be repaid. Falling home prices, which are expected to lead to more defaults among the mortgages held or guaranteed by Fannie and Freddie, contributed to the urgency, regulators said.

The details of the deal have not fully emerged, but it appears that investors who own the companies' common stock will be virtually wiped out; preferred shareholders, who have priority over other shareholders, may also end up with little. Holders of debt, including many foreign central banks, are expected to receive government backing. Top executives of both companies will be pushed out, according to those briefed on the plan.

While it is not yet possible to calculate the cost of the government's intervention, it could rise into tens of billions of dollars and will probably be among the most expensive rescues ever financed by taxpayers. The takeover comes on the heels of a rescue of the investment bank Bear Stearns, which was sold to JPMorgan Chase in a deal backed by taxpayer dollars. Already, the housing crisis has cost investors and consumers hundreds of billions of dollars.

Both presidential nominees expressed support for the government's plans to take over the companies as necessary. Sen. Barack Obama, D-Ill., said as he campaigned in Indiana that not acting could place the housing market in further distress. "These entities are so big and they are so tied into the housing market that it is probably true that we have to take steps to make sure they don't just collapse," Obama told an audience in Terre Haute on Saturday. But he added that the government needed to take steps to guard against Fannie Mae and Freddie Mac ultimately profiting from the government assistance.

Sen. John McCain, R-Ariz., has long been critical of the mortgage finance giants. His running mate, Gov. Sarah Palin, spoke out from a rally in Colorado Springs. "Fannie Mae and Freddie Mac, they've gotten too big and too expensive to the taxpayers," Palin said. "The McCain-Palin administration will make them smaller and smarter and more effective for homeowners who need help."

The big question now is whether the federal government's move to take over Fannie and Freddie will restore investor confidence in the nation's credit markets, help stabilize the stock market and keep loans flowing to creditworthy borrowers.

Fannie and Freddie, by buying mortgages, provide banks and other financial institutions with fresh money to make new loans, a vital lubricant for the housing and credit markets.

As a result of the government's intervention, the cost of borrowing for Fannie Mae and Freddie Mac should decline, because the government will be insuring their debts. Equally important, because the government is backing the companies, they will continue to buy and sell home loans.

But the plan will probably do little to stop home prices from falling further. And foreclosures are almost certain to rise.

Just a week ago, Treasury officials were still considering a wide variety of options for Fannie Mae and Freddie Mac, ranging from doing nothing to taking over the companies completely, according to people with knowledge of those discussions.

The Treasury secretary, Henry M. Paulson Jr., who won authority from Congress last month to use taxpayer money to bolster the companies, always maintained that he hoped never to use that power. But, as the companies' stocks continued to languish and their borrowing costs rose, some within the Treasury Department began urging Paulson to intervene quickly.

Then, last week, advisers from Morgan Stanley hired by the Treasury Department to scrutinize the companies came to a troubling conclusion: Freddie Mac's capital position was worse than initially imagined, according to people briefed on those findings. The company had made decisions that, while not necessarily in violation of accounting rules, had the effect of overstating the company's capital resources and financial stability.

Indeed, one person briefed on the company's finances said Freddie Mac had made accounting decisions that pushed losses into the future and postponed a capital shortfall until the fourth quarter of this year, which would not need to be disclosed until early 2009. Fannie Mae has used similar methods, but to a lesser degree, according to other people who have been briefed.

Representatives of both companies did not return calls or declined to comment.

On Friday, executives from Fannie Mae and Freddie Mac were ordered to appear in the offices of their regulator, James B. Lockhart, in separate meetings, and were told that regulators were exercising their authority to place the companies in conservatorship, which would allow for uninterrupted operation of the companies but would put them under Lockhart's control.

The details of those plans continued to be worked out on Saturday, when the Federal Reserve chairman, Ben S. Bernanke, met with Paulson, Lockhart and key company executives in Washington.

While Freddie Mac's accounting woes make it easier for regulators to force the company into conservatorship, there was more resistance from Fannie Mae, according to people familiar with the discussions. Once the government took action against Freddie Mac, however, confidence in Fannie Mae would certainly waver. Given Fannie Mae's declining financial condition, the company has few options but to concede to the government's demands.

Both companies have the option of challenging the conservatorship and asking for a judicial review.

Accusations of questionable accounting are not new for either company. Earlier this decade, both companies paid large fines and ousted their top executives after accounting scandals.

Freddie Mac's current chief executive and chairman, Richard F. Syron, joined the company in 2003 after the former managers revealed they had manipulated earnings by almost $5 billion.

The following year Fannie Mae's chief executive, Daniel H. Mudd, was promoted to the top spot after that company was accused of accounting errors totaling $6.3 billion. People familiar with Treasury's plan say that both men, as well as other executives, will be forced to leave the companies.

The accounting issues that brought so much urgency to the bailout appear to center on Freddie Mac's capital cushion, the assets that regulators require them to keep on hand to cover losses.

The methods used to bolster that cushion have caused serious concerns among the companies' regulators, outside auditors and some investors. For example, while Freddie Mac's portfolio contains many securities backed by subprime loans, made to the riskiest borrowers, and alt-A loans, one step up on the risk ladder, the company has not written down the value of many of those loans to reflect current market prices.

Executives have said that they intended to hold the loans to maturity, meaning they would be worth more, and they needed not write down their value. But other financial institutions have written down similar securities, to comply with "mark-to-market" accounting rules. Freddie Mac holds roughly twice as many of those securities as Fannie Mae.

Freddie Mac and Fannie Mae have also inflated their financial positions by relying on deferred-tax assets — credits accumulated over the years that can be used to offset future profits. Fannie maintains that its worth is increased by $36 billion through such credits, and Freddie argues that it has a $28 billion benefit.

But such credits have no value unless the companies generate profits. They have failed to do so over the last four quarters and seem increasingly unlikely to the next year. Moreover, even when the companies had soaring profits, such credits often could not be used. That is because the companies were already able to offset taxes with other credits for affordable housing.

Most financial institutions are not allowed to count such credits as assets. The credits cannot be sold and would disappear in a receivership. Removing those credits from assets would probably push both companies' capital below the regulatory requirements.

Regulators are also said to be scrutinizing whether the companies were trying to manage their earnings by waiting to add to their reserves. Both companies have gradually increased their reserves for loan losses — Fannie's reserves today stand at $8.9 billion, and Freddie's at $5.8 billion.

Other companies, like private mortgage insurers, have been quicker to identify large losses and have set aside much greater amounts. Fannie and Freddie have dribbled out bad news with each quarterly announcement, suggesting they may be trying to manage this process.

Regulators are concerned that the companies may have mischaracterized their financial health by relaxing their accounting policies on losses, according to people familiar with the review. For years, both companies have effectively recognized losses whenever payments on a loan are 90 days past due. But, in recent months, the companies said they would wait until payments were two years late. As a result, tens of thousands of loans have not been marked down in value.

The companies have injected their own capital into pools of securities containing these loans, arguing that their new policies are helping more borrowers.

Under conservative accounting methods, changing these policies would not have any impact on the companies' books. However, people briefed on the accounting inquiry said that Freddie Mac may have delayed losses with the change.

"We have just had to nationalize the two largest financial institutions in the world because of policymakers' inaction," said Josh Rosner, an analyst at Graham Fisher, an independent research firm in New York, and a longtime critic of the government-sponsored enterprises. "Since 2003, when these companies' accounting came under question, policymakers have done nothing. Even though they had every reason to know that the housing market's problems would not be contained to subprime and would bring down the houses of Fannie and Freddie."