President Obama announced a major reshuffling of his defense and intelligence teams Thursday, installing some of Washington's most tested public servants at the top as he moves to scale down two wars while teetering on the edge of a third in Libya

The changes come at a critical time, a fact reflected in the battle-tested choices the president made for the positions. Obama named CIA Director Leon Panetta as defense secretary and announced his intention to replace Panetta at CIA with Afghanistan commander Gen. David Petraeus

In Afghanistan, he named Ryan Crocker, the former chief diplomat in Iraq, as the new ambassador to Kabul and Lt. Gen. John Allen as the next military commander there. Allen is deputy commander at U.S. Central Command. 

Obama, in announcing his picks, described them as "leaders of enormous integrity." 

"Given the pivotal period that we're entering, I felt it was absolutely critical that we had this team in place so that we can stay focused on our missions, maintain our momentum and keep our nation secure," Obama said. 

The nominations have won hearty praise from members of Congress, ensuring the men's confirmations for the new positions. A senior administration official said the decisions came after months of careful consideration. The official said Obama chose candidates with deep experience and a respect for one another, and that in Afghanistan, the aim is for a seamless transition. 

Petraeus is expected to leave Afghanistan toward the beginning of September. According to the plan, Allen would spend the next several months preparing for the job, and take the position when Petraeus leaves. 

Sitting Defense Secretary Robert Gates plans to step down June 30, and the hope is to have Panetta confirmed by then. The CIA's deputy director is expected to serve as director on an interim basis, until Petraeus takes over, presumably later in the year. 

In sending Gates off, Obama said he will be remembered as "one of the finest defense secretaries in American history." 

Gates, in brief remarks, called his role as defense secretary "the greatest honor of my life." He said Panetta is the "best possible choice" to succeed him.

Panetta, in a memo to staff, said he accepted his new assignment with a "heavy heart," expressing gratitude for the work being done at the CIA and fondness for his tenure there. 

Though the security landscape in the Middle East and elsewhere is changing drastically, Panetta apparently did not want to assume the role of defense secretary. A senior administration official said Panetta loved being director of CIA, making it difficult for him to leave, but he finally told Obama on Monday evening he would accept the new position.

Panetta said Thursday he would be a "faithful advocate" for U.S. troops at the helm of the Pentagon. 

On the civilian side, Crocker is thought to have a better relationship with Afghan President Hamid Karzai than the current ambassador, Karl Eikenberry. Secretary of State Hillary Clinton was consulted on the change. 

As the leadership changes hands, the president's commanders and advisers will be tasked with overseeing a planned withdrawal of U.S. forces from Iraq by the end of the year, and the start of a withdrawal from Afghanistan this summer. Petraeus, though, has said the withdrawal will be conditions-based, and will only mark the start of the process. 

At the CIA, Petraeus would also have significant influence over U.S. operations in neighboring Pakistan, where the agency is coordinating deadly drone attacks -- which have become increasingly unpopular in Pakistan. He could also play a big role, along with the next defense secretary, in shaping the mission in Libya should U.S. and NATO forces continue to be engaged in that country. 

Muammar al-Qaddafi has clung to power since Obama authorized military strikes on Qaddafi's forces more than a month ago. The White House has refused to commit to military boots on the ground, but CIA agents are said to be helping Libyan rebels organize.