IT WAS another of those frantic weeks that were never meant to happen in the world's most advanced economy. On July 13th Hank Paulson, America's treasury secretary, stood on his department's steps like some emerging-market finance minister, and unveiled an emergency plan to save Fannie Mae and Freddie Mac, two mortgage giants that owe or guarantee $5.2 trillion. Two days later, Ben Bernanke, chairman of the Federal Reserve, put the fear of God into the markets, warning Congress of a foul amalgam of inflation and economic distress.

The immediate lesson is that the financial crisis, nearly a year old, is far from over (see our coverage, beginning with this article). Gloomy investors are gunning for banks of all types. In America the prices of houses and shares are falling, and the cost of food and energy has soared. Consumers are almost certain to cut back. The euro-area economy may have shrunk in the latest quarter. Central banks around the world are having to raise interest rates to curb inflation, and the dollar looks vulnerable. Even if the downturn proves less sharp than pessimists fear, it is likely to last longer than optimists hope.

Freddie and Fannie have changed that equation only slightly. Their importance lies in what their rescue says about the financial system. At Fannie and Freddie—and, shockingly, at the investment banks—the profits were privatised, but the risks were socialised. One Republican senator complained that he thought he had “woken up in France”. Mr Paulson was still right to intervene: the collapse of Fannie and Freddie would have been a catastrophe. But by not formally nationalising them, he has let down taxpayers and made the same deeply uncapitalist mistake the British government initially made with Northern Rock, a failed mortgage bank it tried to prop up.

Mark to market, or market to Marx?

The debt is what matters with Fannie and Freddie, but the shares were the trigger. When investors realised they would eventually need more money to cover their looming losses, there was a run on the stock. This rapidly became a test of a tacit government pledge to back their debt. Had the government hinted that it wanted to wriggle free from its vague promises, the debt would have crashed; the banking system would have been crippled by new losses; foreign investors would have fled a country that broke its word; and the housing market, a trifle short of lenders just now, would have lost its main backers. Mr Paulson vowed to lend Fannie and Freddie money and buy their shares if necessary. They could also borrow from the Fed. The next day investors queued up to buy Freddie's bonds.

That is plainly not the end of it for the taxpayer. It seems quaint that critics once complained that finance was all about untrammelled markets and deregulation. On July 11th regulators took over IndyMac Bancorp, a Californian thrift, after the second-biggest bank failure in American history. After the rescue of Bear Stearns in March, the Fed agreed to back investment banks with its balance sheet. Congress is chewing over a small subsidy to troubled mortgage owners. If another large bank became vulnerable, more rescues would beckon.

Capitalism rests on a clear principle: those who get the profits should take the pain. For the system to work, bankers sometimes need to lose their jobs and investors their shirts. Yet were a collapsing Bear Stearns or Fannie Mae to sow destruction for the sake of a principle, it would impose a terrible price in lost jobs and output on everyone else. The unpalatable truth is that by the time a financial crisis hits, the state often has to compromise—to impose as much pain as it can, of course, but to shoulder a large part of the losses nonetheless.

That formula comes at a heavy price. Fannie and Freddie were supposed to help Americans buy their own homes, by making the mortgage market work better. But it has been an awful deal for the taxpayer—a Fed economist calculated the implicit debt-guarantee was worth a one-off sum of between $122 billion and $182 billion. Because Fannie and Freddie barely lowered the cost of borrowing, little of this subsidy went towards boosting home ownership. Instead, just over half—about $79 billion—went straight to their shareholders.

Normal financial-services firms should have been dealing in the safe, middle-of-the road mortgages that Fannie and Freddie specialise in. Except that they were crowded out into subprime mortgages. Fannie and Freddie should never have grown so large. Except that they wanted to exploit the margin between the government-guaranteed borrowing costs and the commercial lending income. They should have been stopped by Congress and their regulator. Except that they spent some of their subsidy on a fierce lobbying machine.

Fannie must not

In the past, we have argued for privatising Fannie and Freddie completely. But now that the guarantee is explicit, Mr Paulson should seek to secure the gains for taxpayers and treat Fannie and Freddie like one of their own mortgages, by nationalising them, breaking them up and selling them on. That would almost double the public debt—but only in book-keeping terms. The liability is already implicit (as at Northern Rock), and, unlike Treasuries, it is ultimately backed by housing as collateral.

It is harder to know what to do about all those other implicit state guarantees—seemingly to any financial outfit. The first instinct should be to make sure someone suffers; shareholders and managers at the very least. It was a valuable lesson when some of IndyMac's depositors could not get hold of their money because they exceeded the government guarantee.

If you cannot let firms fail in a bust, then you must contain them in the boom. That helps explain why the investment banks now need more supervision; why financial firms should have to hold more capital as a boom gathers pace; and why monetary policy should lean against rising asset prices. Regulation is necessary, but beware the state being seduced into taking on duties it cannot possibly carry out well. As Fannie and Freddie show, regulators are easily captured and outwitted. The best controls are transparency and competition. When possible the government needs to stand back. Sadly, it failed to do so in the American mortgage market.