General Petraeus, while intimately familiar with Afghanistan and its myriad problems, is inheriting direct command at a particularly fraught moment. Seven months into President Obama’s surge of forces, there is little evidence that the addition of tens of thousands of troops has beaten back the Taliban, or that Mr. Karzai’s government will soon be able to hold and administer territory the United States helps it retake.

Mr. Obama admitted as much indirectly on Wednesday in the Rose Garden when he said: “We have a clear goal. We are going to break the Taliban’s momentum.” They were the same words he used seven months ago at West Point in announcing the surge, and as one senior official said, “The president was acknowledging that a third of the way into the surge, the momentum has not been broken.”

One senior administration official noted that General McChrystal and Mr. Karzai “just came off the most constructive week we’ve had in a while with Karzai” when the two men traveled through Kandahar, the site of the next big counterinsurgency push. General McChrystal reported back that Mr. Karzai finally seemed deeply engaged in the details of the effort to regain control over the sprawling city, one of the Taliban’s home bases, administration officials said.

General Petraeus will now be responsible for executing the Kandahar offensive into the spiritual heart of the Taliban. White House and Congressional officials say they expect he will be confirmed quickly  probably by the end of next week.

General McChrystal had already prepared his brief resignation letter when he walked into the meeting with Mr. Obama; he left quickly afterward, saying nothing to the reporters who converged near him. Relieved of his post, he did not attend a regularly scheduled National Security Council meeting that included all the same administration officials whom he or his staff disparaged in the article.

“I welcome debate, but I won’t tolerate division,” the president said afterward. He said that it was crucial for American troops and military officers to observe a “strict adherence to the military chain of command and respect for civilian control over that chain of command.”

In the Rolling Stone article, General McChrystal and his aides belittled many of their civilian counterparts on the Afghanistan strategy team.