General Motors took an unexpected detour Thursday, as its chief executive said he is stepping down just days before the company plans to file what may be history’s biggest initial public offering of stock.

At the same time, GM announced its biggest profit in six years, a $1.3 billion turnaround quarter as the nation’s top automaker prepares to pay back the government’s $51 billion bailout a little more than one year after emerging from bankruptcy.

It’s not typical for a chief executive to announce his resignation on the eve of an IPO, but that’s what the 68-year-old Edward E. Whitacre Jr. did, saying he will be succeeded on Sept. 1 by Daniel Akerson, a GM director and a managing director of the Carlyle Group, a Washington private-equity firm. The Obama administration appointed Akerson, 61, to GM’s board a year ago after forcing G. Richard Wagoner Jr. to step down as chief executive.

“My goal in coming to General Motors was to help restore profitability, build a strong market position and position this iconic company for success. We are clearly on that path,” said Whitacre, the former AT&T chief who took over GM’s top job in December after the board fired Wagoner’s successor, Fritz Henderson. Henderson faltered in getting rid of unwanted company assets, such as Saturn and Saab, and was criticized for being a GM lifer, unable to make fundamental change.

“A strong foundation is in place and I am comfortable with the timing of my decision,” said Whitacre, who will exit as chief executive in less than one month but will remain GM chairman through the end of the year.

GM’s filing to sell shares of stock could come as early as today, with the launch itself coming later this year, according to sources close to the situation who spoke on the condition of anonymity because the company has not yet filed. The government owns 61 percent of GM, which is hustling to shrug off the “Government Motors” tag. GM has paid back $7 billion of a government aid package worth $50.7 billion. The remainder of the payback will come from the history-making IPO, which some analysts guess will bring as much as $70 billion.

Unlike with the Wagoner sacking, both the government and GM said Whitacre’s exit was solely decided by the company.

“The board advised (the government) of the decision, but they did not have to approve it,” said GM spokesman Greg Martin said.

Like Whitacre, Akerson has a background in telecommunications, with top jobs at Nextel, MCI Communications and XO Communications. He joined the Carlyle Group, in 2003 and is head of its global buyout division and a member of the firm’s executive committee.

He became the chief architect of GM’s bankruptcy after he was put on the GM board by former government “car czar” Steve Rattner a year ago, thanks to his experience in finance and turnaround management. Akerson was known as a tough critic of GM’s internal attempts at a makeover, arguing it did not go far enough to change the company’s sluggish culture.

Whitacre’s resignation stunned auto analysts.

“It was a big surprise, and it caught everybody off guard,” said Jeremy Anwyl, chief executive of auto site Edmunds.com. “But when you step back, it makes all kinds of sense.” Anwyl said that part of an IPO is the “road show” — when the company’s top executives travel the country, seeking investors. “If you’re doing a road show, investors are entitled to know who the managers are for the foreseeable future. Instead of dodging the question of succession planning, GM is answering it in the most tangible way.”

Once the backbone of American manufacturing, GM and its nearby rival, Chrysler, now stand at turning points.

One year ago, both companies were emerging from government-backed bankruptcy on unsteady legs. Chrysler survived liquidation thanks to a hasty marriage to Italy’s Fiat, which now owns 20 percent of the company and has management control. The government took a more direct interest in GM, first sacking Wagoner, who is now a Washington Post Co. director, and taking a 61 percent ownership stake in the company. Ford was the only one of Detroit’s Big Three to pass up a government handout.

Earlier this week, Chrysler said it narrowed its second-quarter losses and plans to bring a small and popular Fiat to the U.S. market later this year. GM, thanks to cost cutting and solid sales among its four remaining brands — Chevrolet, Cadillac, Buick and GMC — swung to second-quarter profitability.

Much of GM’s success will depend on the fate of the 2011 Chevrolet Cruze, the first mass-produced new vehicle rolled out by the new GM. Starting at less than $17,000, the Cruze enters the crowded and competitive field of high-mileage compact family sedans, going up against Toyota, Honda and several other automakers.