A man walks through a pedestrian bridge near the General Motors headquarters in Detroit. (Joshua Lott /REUTERS)

The Treasury Department announced Monday the sale of its remaining shares in General Motors, closing the books on one of the most controversial government interventions of the financial crisis.

The government will lose $10 billion on the deal, which kept the automaker from collapsing.

At the height of the meltdown, the Obama administration took majority stakes in GM and Chrysler to prevent them from going under. The deal rankled some lawmakers, especially when executives flew their private jets to Washington to beg for a lifeline. Treasury, nevertheless, floated the automakers about $80 billion.

The government has recovered $38.4 billion of the nearly $50 billion it invested in GM. In 2011, Treasury closed the books on its $12.5 billion bailout of Chrysler and took about a $1.3 billion loss.

Other bailouts, including the rescue of American International Group, have turned a profit for taxpayers.Government officials have long anticipated that saving Detroit would come at a cost, but letting the automakers fall would have been far worse, they say.

“Our auto industry was on the verge of collapse, threatening to destroy more than 1 million jobs and cost billions in lost personal savings,” Treasury Secretary Jacob Lew said in a call with reporters. “The economic stakes were high. President Obama understood that inaction was not an option.”

Obama expanded a rescue initiative that began in 2008, during the Bush administration. GM was teetering on the edge of failure amid declining auto sales that resulted in $70 billion in losses between 2005 and 2008. The administration’s auto task force steered the company through a bankruptcy that wiped out shareholders and pushed out then-chief executive G. Richard “Rick” Wagoner Jr.

The task force, led by financier Steven Rattner, forced changes that resulted in GM plant closings and 2,000 dealers being cut from the sales network. GM emerged with fewer brands and a streamlined business that has turned profits for the past three years.

“When things looked darkest for our most iconic industry, we bet on what was true: the ingenuity and resilience of the proud, hardworking men and women who make this country strong. Today, that bet has paid off. The American auto industry is back,” President Obama said in a statement Monday.

In 2010, Treasury began selling its stake in the company with an initial public offering priced at $27.50 a share. GM has repurchased some of its stock from the government, buying 200 million shares for $5.5 billion last year.

The government’s divestment allows GM to shed the last vestiges of the bailout, including restrictions on executive pay and dividends to shareholders.

For Treasury, selling its shares of GM brings it closer to fully winding down the crisis-era investments made through the Troubled Assets Relief Program. It has recovered $432.7 billion on all TARP investments, compared with $421.8 billion disbursed.