The U.S. government essentially closed the books on TARP with a $15.3 billion profit.

Treasury sold its remaining shares Friday in Ally Financial, its last remaining major stake from the $426 billion bailout of banks and the U.S. auto industry.

The Troubled Asset Relief Program was passed in 2008, in the wake of Lehman Brothers' bankruptcy, as the nation's financial system was on the verge of collapse and economists feared another Great Depression. At the height of the bailout, Treasury owned a significant stake in all of the major U.S. banks, such as Citigroup (C) and Bank of America (BAC), two of the nation's Big Three automakers -- General Motors (GM) and Chrysler Group (FCAM) -- as well as one of its largest insurers, AIG (AIG).

But with the sale of the Ally (ALLY) stock, Treasury now only holds stakes in 35 small community banks.

Ally Financial was formerly known as GMAC, and had been GM's finance arm. While it was hurt by the plunge in car sales, its move into subprime mortgages did the most damage. Ally was bailed out as part of the auto industry bailout, since its failure would have left a significant portion of the nation's car dealers without the financing they needed to stay open.

Treasury received $1.3 billion from its final sale of Ally stock Friday, leaving it with a $2.4 billion profit on the company.

Overall, the auto bailout was the one big money loser for TARP. Even with the Ally sale, taxpayers lost about $9.2 billion.

But opting not to bail out the auto industry likely would have proven far more costly, since GM, Chrysler and many car dealers likely would have gone out of business without the government's help.

If GM and Chrysler had gone under, it would have cost an estimated $39 billion to $105 billion in lost tax revenues as well as assistance to the unemployed, according to a study from the Center for Auto Research. And the government also would have been on the hook for billions in promised pension payments to autoworkers.