General Motors Co Chief Executive Ed Whitacre resigned suddenly on Thursday as the automaker posted its biggest quarterly profit in six years and readied an IPO expected to allow the U.S. government to relinquish its majority stake.

Whitacre, 68, who has served just eight months as chief executive of the top U.S. automaker, said he would resign on September 1, to be replaced by Dan Akerson.

Akerson, 61, was named to GM's board by the Obama administration a year ago when the automaker was restructured in bankruptcy with $50 billion of U.S. government funding.

A veteran deal maker and managing director of The Carlyle Group for the past seven years, Akerson spearheaded some of the private equity firm's biggest recent deals including the buyout of energy company Kinder Morgan.

Whitacre's departure had been expected but the timing of his announcement caught even GM insiders off guard, just a day ahead of GM's expected filing for a landmark stock offering.

A former AT&T chief executive, Whitacre had been expected to stay on at GM through the filing of the IPO. As recently as last week he had described plans for a series of meetings with big investors to tout the offering.

The abrupt management change could delay GM's IPO filing from Friday by a few days as the documents are reviewed and new management is added as a risk factor in the filing, reflecting the shake-up, a source familiar with the matter said.

The U.S. Treasury said GM's board made the decision, which did not require government approval.

Whitacre, who continued to commute from his home in Texas during his stint as CEO of the Detroit-based company, had said repeatedly that he would be an interim leader.

It was obvious that I was not going to be at GM for the long haul, Whitacre said at the end of a conference call to discuss the company's second-quarter earnings.

We have put a strong foundation in place, so I am very comfortable with my timing.

Akerson, also a former CEO at Nextel, will become GM's fourth chief executive in just a year and a half, underscoring the challenge in remaking the corporate culture of an automaker still in the early stages of a turnaround.

Whitacre had become famous at GM for his impromptu plant visits and his disdain for what he saw as the automaker's overly analytical and slow-moving decision making.

Jeffrey Sonnenfeld, a management expert at the Yale School of Management, said Whitacre was having a positive impact at GM and should have stayed on under normal circumstances.

The instability certainly is a shock to insiders, it's stunning to outsiders, and you don't usually have that happen, Sonnenfeld said. There is a story here that we are not getting.

He added: Clearly this was not part of a planned succession.

DRIVING THE TURNAROUND?

Separately, GM posted a second-quarter profit of $1.3 billion in evidence of a turnaround driven by cost-cutting in its 2009 bankruptcy and better sales in the United States.

The second-quarter profit was the largest since 2004, when the U.S. auto market was still booming with annual sales of near 17 million vehicles and GM's brands accounted for more than one in four purchases of new cars and trucks.

The results reflected a 47 percent snap back in global production from the depressed levels of a year earlier when GM began operating under bankruptcy.

Revenue rose to $33.2 billion from $31.5 billion in the first quarter.

Analysts expect the company to use the results to build the case for a record stock offering and allow the U.S. government to reduce its 61 percent ownership stake.

A successful GM IPO would provide the Obama administration with evidence that the unprecedented and unpopular intervention in the U.S. auto industry has been a financial success.

Europe, where GM is still struggling to restructure its Opel unit, remained a notable weak link for the automaker with an operating loss of $160 million.

North America had an operating profit of $1.6 billion. International operations, including GM's China joint ventures with SAIC and Wuling, had an operating profit of $672 million.

Despite GM's recovery over the past year, analysts say it still faces a challenge in winning back consumers because of the lingering stigma from its bailout and the Government Motors label from critics.

GM lost about $88 billion between 2005 and 2009 when it was driven into bankruptcy by plunging sales and tight credit.

GM's U.S. market share was just over 19 percent in the quarter that ended in June, down from almost 21 percent a year earlier when it was still selling the now-scrapped Saturn, Saab, Pontiac and Hummer brands.

GM's results show it is trailing its more successful and smaller rival Ford Motor Co, which posted a second-quarter profit of $2.6 billion, but ahead of Chrysler, which lost $172 million.

Sources told Reuters on Wednesday that the largest U.S. automaker had secured a $5 billion credit facility, marking its return to the capital markets a year after it emerged from a government-funded landmark bankruptcy.

GM Chief Financial Officer Chris Liddell declined to comment when asked about the credit facility. He said the arrangement was one of the building blocks GM needed to restore its balance sheet.

(Additional reporting by Bernie Woodall in Detroit, Megan Davies in New York and John Crawley in Washington; Editing by Maureen Bavdek, Gary Hill)