David Petraeus, who had led U.S war efforts in Afghanistan and Iraq, retired from the Army Wednesday to become the head of the CIA.

The four-star general had served in the Army for 37 years before accepting President Barack Obama's offer of the CIA director job. He will officially start on Sept. 6, succeeding Leon Panetta, who moved out of the spy chief job to succeed retiring Robert Gates as secretary of defense. John Allen, a four-star general, succeeded Petraeus in July as the commander in Afghanistan.

After a long military career, many had expected Petraeus would ascend to its top post, chairman of the Joint Chiefs of Staff. But he decided to hang up his uniform to head the nation's most well-known intelligence agency. I wanted this job, he said at his Senate confirmation hearing for the CIA job. I am taking off the uniform I have worn for 37 years to do this the right way.

Petraeus, 58, is credited for turning around insurgency in Iraq and for managing a tough situation in Afghanistan after former general Stanley McChrystal was relieved of his duties following a revealing Rolling Stone story. Some have labeled Petraeus as King David for his success in ending a lot of the insurgency that was plaguing Iraq.

At a September 2008 ceremony in Baghdad marking the end of Petraeus' command there, Gates told him, I believe history will regard you as one of our nation's great battle captains.

Petraeus could have stayed with the Army, but chose to leave to avoid confusion about his new role.

I have a certain profile in various parts of the world, he told the Pentagon Channel in an interview Aug. 18. And were I to travel there in uniform, it might create some confusion, frankly, as, you know, 'Who is this guy? He's still in uniform. Is he the director of the CIA or is he actually something else?'

Adm. Mike Mullen, the chairman of the Joint Chiefs of Staff, has planned a big retirement ceremony for Petraeus at the Pentagon on Wednesday.