The fortunes of the once-beleaguered auto lender Ally Financial have risen with the rebirth of the car industry. Booming demand for auto financing has helped the firm regain its footing after the economic crisis brought it to the brink of collapse.

Now Ally is close to shaking off the last vestiges of that time: its bailout.

On Thursday, the Treasury Department said it plans to sell 410,000 shares of Ally for $3 billion, reducing the government’s stake in the company from 64 percent to 37 percent.

The department said that, once the sale is complete, the government will have recovered about $15.3 billion, or 89 percent of the $17.2 billion it handed to Ally through the Troubled Assets Relief Program. A portion of the returns is the result of dividend payments.

“This is a very positive outcome for Ally and for the U.S. taxpayer, and the strong investor interest is a testament to the significant transformation of the company,” Michael Carpenter, chief executive of Ally, said in a statement.

It has been a rough road for Ally. The company, formerly known as GMAC, once provided about three-quarters of the financing for auto dealers to purchase vehicles from General Motors and Chrysler.

But declining car sales and write-downs on auto leases in 2008 resulted in a loss of $2.1 billion. Ally then was brought to its knees by its subprime mortgage business, which sustained even more dramatic losses.

In the years since the downturn, the company has been mired in litigation tied to its former mortgage subsidiary, Residential Capital (ResCap), making it difficult for Ally to repay the government. But it was released from ResCap’s legal liabilities in December, when a judge approved the mortgage firm’s bankruptcy plan.

Ally’s reputation took a hit that same month, when the Consumer Financial Protection Bureau slapped the firm with a $98 million penalty for allegedly charging minority borrowers higher interest rates than whites. It was the government’s largest-ever auto-loan discrimination settlement.

Around the same time, the Federal Reserve granted Ally financial holding company status, which allowed the company to continue selling insurance products to auto dealers.

Litigation expenses and dwindling mortgage revenue reduced Ally’s profits by 76 percent in the third quarter, the most recent period for which the company has reported earnings. Auto loan originations were flat at $9.6 billion, but earnings on auto assets rose 8 percent year over year. Income from the insurance business climbed to $83 million from $13 million.

“Ally has been a great recovery story,” said Robert Smalley, head of the credit desk analyst group at UBS Securities. “In the second half of the year and certainly in 2015, the story will move to sustaining and growing earnings rather than recovery.”

Since 2011, Ally has been planning to conduct an initial public offering, which was put on hold as the company waded through the ResCap litigation. Ally sold 216,667 shares for $1.3 billion in November to raise its capital levels, and it has not taken the IPO off the table.

“An IPO continues to be a viable option, but the U.S. Treasury will ultimately determine how and when it will dispose of its common equity stake in Ally,” company spokeswoman Gina Proia said in an e-mail.

For its part, Treasury said in a statement that it will continue to work with Ally to further wind down the investment through either “a public offering, private sale of its common shares or other alternatives.”

One of the staunchest critics of Treasury’s wind-down of the bailout, Christy Romero, the special inspector general for TARP, praised the progress being made on recouping the money invested in Ally. But Romero, who wrote a stinging report last year on the slow process, continued to press the department for a “concrete” exit plan.

“TARP assistance to GMAC, rebranded as Ally, was remarkably different than aid to other auto companies because GMAC was the only auto company in TARP that Treasury did not require to submit a viability plan outlining how it would restructure,” she said. “We continue to urge Treasury to ensure that Ally exits TARP in a way that maintains its financial stability.”