The government’s planned takeover of Fannie Mae and Freddie Mac, expected to be announced as early as this weekend, 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 wind up with little. Holders of debt, including many foreign central banks, are expected to receive government backing. Top executives at 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 in a deal backed by taxpayer dollars. Already, the housing crisis has cost investors hundreds of billions of dollars.