President Barack Obama relieved Gen. Stanley McChrystal of commanding forces in Afghanistan, swiftly acting in the wake of derisive comments McChrystal and his aides made to Rolling Stone magazine, according to a White House official.

Gen. David Petraeus, the head of the military’s Central Command and the architect of the surge of forces into Iraq in 2007, will take over as the commanding general in Afghanistan, administration officials said.