General Motors Co Chief Executive Ed Whitacre resigned on Thursday in an abrupt shift that came as the automaker hit the homestretch in preparing a stock offering to pay back its controversial bailout.

Dan Akerson, 61, a veteran private equity investor little known in the auto industry, replaces Whitacre as of September. Akerson had been appointed by the Obama administration as one of the directors meant to safeguard the government's $50 billion financing to restructure GM.

Whitacre's departure had been expected, but the timing of his announcement caught even insiders off guard, a day before the top automaker was expected to file the paperwork for a landmark stock offering just over a year after its emergence from bankruptcy.

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

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

We still have important work ahead of us, but I am confident that we are building the foundation for GM's long-term success, Akerson said in a hastily arranged appearance at the end of a conference call to discuss the automaker's second-quarter earnings.

The question of Whitacre's tenure was raised at a GM board meeting about two weeks ago when former director Kent Kresa, 72, tendered his resignation, according to a person with knowledge of the private proceedings.

Kresa had been on the GM board since October 2003 and had reached the mandatory retirement age.

At the same meeting, Whitacre, 68, made it clear that he wanted to step down as CEO at the end of the year, about a month after GM is expected to launch an IPO on track to be one of the largest ever.

Board members asked Whitacre if he would consider committing to a longer term, but when he would not, the board turned to Akerson, who had been a candidate for the CEO post after the 2009 departure of former CEO Fritz Henderson, according to the person.

The U.S. Treasury said GM's board made the decision on the CEO change. Officials who asked not to be named said that there had not been any tension between Whitacre and the Obama administration on the direction of GM.

Even so, the sudden nature of the executive change could have repercussions for the perception of GM and its IPO. Most immediately it could delay GM's planned IPO filing on Friday by a few days, sources with knowledge of the process said.

The instability certainly is a shock to insiders; it's stunning to outsiders and you don't usually have that happen, said Jeffrey Sonnenfeld, a management expert at the Yale School of Management.

South Beach Capital Markets Advisory Corp President Bruce Foerster said the shakeup at the top of GM risked having investors add a new risk premium to its upcoming IPO.

You needed the sun, moon and stars all aligned and now they're out of whack again, said Foerster.

A 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.

His appointment as GM CEO thrusts an executive known for quiet deal making into the spotlight as salesman in chief for the top U.S. automaker.

BIGGEST PROFIT IN SIX YEARS

Separately, GM posted a second-quarter profit of $1.3 billion as 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.

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 that it is ahead of Chrysler, which lost $172 million.

But 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 the unprecedented and unpopular intervention in the U.S. auto industry has been a financial success.

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

Sources told Reuters on Wednesday 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.

Chief Financial Officer Chris Liddell declined to comment in detail 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 and Soyoung Kim in New York and John Crawley in Washington; editing by Maureen Bavdek, Gary Hill, Andre Grenon and Carol Bishopric)