Tributes have been paid to him at a ceremony at the Fort Myer US army post in Virginia to mark his retirement.
Gen Petraeus will take over at the helm of the CIA on 6 September.
Admiral Mike Mullen, chairman of the US chiefs of staff, hailed Gen Petraeus' service during the ceremony on Wednesday, saying: "When it comes to the art of impossible there's Gen Dave Petraeus and then there's everybody else."
"Quite simply, Gen Dave Petraeus set the gold standard for command in the modern era," Adm Mullen added.
Considered one of America's most influential military officers, the four-star general spent 37 years in the armed forces.
Gen Petraeus solidified his reputation after taking over in Iraq during a critical period in 2007.
He then took over in Afghanistan in July 2010 after the resignation of Gen Stanley McChrystal.