The U.S. government ended up losing $10.5 billion on the General Motors bailout, but it says the alternative would have been far worse.

The Treasury Department sold its final shares of the Detroit auto giant on Monday, recovering $39 billion of the $49.5 billion it spent to save the dying automaker at the height of the financial crisis five years ago.