(CNN) -- U.S. Army Gen. David Petraeus, who served as the top U.S. commander in Iraq and Afghanistan, ended his military career Wednesday to take the reins at the CIA.
"Our journey with the U.S. military has been amazing one," he said, speaking for himself and his wife Holly at his retirement ceremony after 37 years in the Army. The ceremony was held at Joint Base Myer-Henderson Hall in Virginia.
He added that the journey was not coming to an end, "even though we're about to begin an exciting new journey with another extraordinary organization."
Adm. Mike Mullen, chairman of the Joint Chiefs of Staff, praised Petraeus' "historic leadership."
Among Petraeus' accomplishments, Mullen said: overseeing the "Herculean" task of organizing and training a new Iraqi Army, an "astounding" achievement.
Petraeus is also the architect of the military's counterinsurgency strategy. Mullen noted that Petraeus assembled "an incredibly talented and diverse team, drafting the Counterinsurgency Field Manual, which would not only serve as the blueprint for our successes in Iraq and Afghanistan, but would also go on to become a best-seller."
Petraeus, 58, said the U.S. military has "learned since 9/11 that we don't always get to fight the wars for which we're most prepared or most inclined. Given that reality, we will need to maintain the full spectrum capability that we have developed over this last decade of conflict in Iraq, Afghanistan, and elsewhere."
He added that he departs with a "sense of great confidence in our military and in our country. Despite the innumerable challenges that face our nation and our world, I believe in our citizens, our system of government, and above all our men and women in uniform."
President Barack Obama cited Petraeus' experience in working with the CIA on counterinsurgency efforts in the field as a reason for his nomination as its director.
Petraeus assumes his new role next week, on September 6.
As the top U.S. commander in Iraq, Petraeus was dubbed "King David" for turning around what seemed like a losing battle.
He took over in Afghanistan in July 2010 after the retirement of Gen. Stanley McChrystal, whose departure came on the heels of unflattering remarks he made about administration officials in a Rolling Stone magazine article.
On July 18, Petraeus handed over Afghan command to Gen. John Allen.
Petraeus graduated in 1974 from West Point and began his career as a second lieutenant in the infantry. He went on to become arguably the most influential general of his generation, and Esquire magazine called him one of the most influential people of the 21st century.
"I wanted this job," Petraeus said at his Senate confirmation hearing. "I am taking off the uniform I have worn for 37 years to do this the right way."