For more on Afghanistan and Gen. Stanley McChrystal, go to Afghanistan Crossroads.
Washington (CNN) -- Defense Secretary Robert Gates said Thursday that he agrees with President Obama's decision to replace Gen. Stanley McChrystal with Gen. David Petraeus as the top U.S. commander in Afghanistan.
Comments by McChrystal and his staff in a Rolling Stone profile were "unacceptable" and "inconsistent" with the "high standards" expected of military officials, Gates said.
Obama relieved McChrystal of command of the Afghan war on Wednesday, a day after Rolling Stone published critical comments about top White House officials by members of McChrystal's staff.
The appointment of Petraeus, the head of U.S. Central Command, is the "best possible outcome to an awful situation," Gates said.
Petraeus was chosen because he was the only general officer who could take over without "a missed beat," the defense secretary said.
He said Obama first raised the idea of appointing Petraeus to replace McChrystal during a meeting Tuesday afternoon in the Oval Office.
Earlier, a senior Pentagon official told CNN's Barbara Starr that Gates backed keeping McChrystal because he was vital to the war effort in Afghanistan, but Gates was overruled.
The official has direct knowledge of the events but declined to be identified because of the internal administration discussions.
Gates initially was furious about the Rolling Stone article but said McChrystal had to stay in command because the war is at such a critical point, a second source -- who also asked not to be named on internal administration discussions -- told CNN.
But as it became clear the White House didn't feel same way and the issue was not going to fade, Gates shifted his position and agreed that keeping the general would be an untenable distraction.
Technically, McChrystal resigned.
It's still unclear whether the president had made up his mind before sitting down with McChrystal, but CNN has learned that during their one-on-one meeting, Obama gave the general a chance to defend himself.
"The president asked him about the [Rolling Stone] article," said a senior administration official.
McChrystal "tried to explain the situation," the official said.
That senior administration official, who briefed reporters, said that once Obama accepted McChrystal's resignation, he wasted no time finding his replacement.
After McChrystal walked out of the White House following his 30-minute face-to-face meeting with the president, Obama immediately huddled with a team of advisers to decide who would replace McChrystal.
That group included Vice President Joe Biden; Gates; Adm. Mike Mullen, chairman of the Joint Chiefs of Staff; national security adviser Jim Jones; and Chief of Staff Rahm Emanuel.
For 45 minutes, they mulled over the president's options. The White House earlier had asked for a list of possible replacements.
Petraeus offered continuity, being familiar with all the players in the region and NATO partners.
Then Obama called Petraeus, who was already in the White House Situation Room, into the Oval Office to ask him to take over the mission in Afghanistan.
That meeting lasted for 40 minutes, and Petraeus agreed.
The senior administration official said Petraeus did not consider it a demotion.
Obama acknowledged the move was not "the normal course" for a top general to go from being in charge of Central Command to taking command in Afghanistan.
The president also acknowledged it was "a sacrifice for Petraeus."
Obama then went to the Situation Room, where his national security team was waiting.
The senior administration official described the president as "stern" as he walked the team through his decision.
The official said the president told everyone, "We need to remember why we're doing this."
Obama went on to explain that it was understandable to have disagreements or tension within his security team, but when those disagreements turn petty, that does not serve the men and women fighting for the mission.
The president expressed "regret" and "sorrow," saying that "this was a sad day," the senior administration official said.
Then Obama wrapped up the meeting and called Afghanistan's President Hamid Karzai to explain his decision.
McChrystal and Karzai had been close, according to administration and Pentagon officials.
The president then went to the Rose Garden to announce his decision to the American people.
Since then, Obama has talked to British Prime Minister David Cameron, House Speaker Nancy Pelosi and Sens. Harry Reid, Carl Levin and John McCain, according to White House spokesman Tommy Vietor.
He is urging the Senate to follow his lead and to confirm his nominee quickly.
CNN's Suzanne Malveaux and Dan Lothian contributed to this report.