An article in Rolling Stone magazine this week led to the ouster. In the article, McChrystal and his aides make disparaging remarks about civilian U.S. leaders, including Obama and Vice President Joe Biden.
The choice of Petraeus overcame the biggest obstacle to removing McChrystal, the threat of a command vacancy that would slow down the Afghan campaign and force the administration to back off its timetable, which includes troop withdrawals that are scheduled to begin next summer.
In Petraeus, the head of the military's Central Command overseeing U.S. forces in the Middle East, Obama found the general who helped craft the Afghanistan strategy and has been closely supervising it.
The Rolling Stone article portrayed McChrystal and his team speaking bluntly and frankly in unguarded moments, insulting and mocking civilian leaders.
Many of the most offensive comments in the article came from unnamed aides. Still, military officers said that the article showed that McChrystal had allowed an undisciplined command climate to develop.
The change in war leadership comes at a critical time, with doubts growing among members of Congress and the American public about the war and questions arising over the Afghan government's commitment to the U.S. strategy.
But in some ways, the appointment of Petraeus actually could help the war effort, because he is skilled in areas in which McChrystal and his team were struggling.
While overseeing Iraq, Petraeus was able to explain U.S. strategy to the public and to lawmakers on Capitol Hill, even at the beginning of the unpopular troop build-up as violence soared and the approach seemed to falter.
In Afghanistan, U.S. and allied forces have encountered setbacks in two of the year's primary campaigns, and Afghan President Hamid Karzai has voiced doubts about the U.S. commitment to the region. Obama reassured him yesterday.
Officials said that Petraeus is likely to use his upcoming Senate confirmation hearing to quell some of the doubts.
In Iraq, Petraeus also showed he was adept at forging relationships, with local Iraqi leaders and with U.S. diplomatic officials.
McChrystal made no remarks in Washington, but the U.S. military command issued an apology on his behalf from Kabul. In his statement, McChrystal said he was committed to the allied forces and he supported Obama's strategy.
"It was out of respect for this commitment - and a desire to see the mission succeed - that I tendered my resignation," McChrystal said.