In an elaborate ceremony in a marble-lined rotunda of a former Saddam Hussein palace on the outskirts of the capital, Petraeus handed off to Odierno the responsibility for leading U.S. and coalition forces at a stage in the still-unpopular war that appears far more hopeful than when Petraeus assumed command 20 months ago.
Petraeus leaves behind a heavy dose of caution, reflected in his recommendation to President Bush that he maintain 15 combat brigades in Iraq through the end of the year instead of pulling out one or two, as many had expected.
And despite the security gains, insurgents retain the ability to carry out devastating attacks.
On Monday evening, a female suicide bomber blew herself up among a group of police officers northeast of Baghdad, killing at least 22 people. Hours earlier, car bombs in the capital killed 13 people.
Defense Secretary Robert Gates presided over Tuesday's ceremony, recalling the perils faced by Petraeus at the start of his tour in February 2007.
"Darkness had descended on this land," Gates said. "Merchants of chaos were gaining strength. Death was commonplace," and people around the world were wondering whether any Iraq strategy would work.
Gates praised Petraeus and Odierno for their accomplishments together in 2007, when Odierno served as the No. 2 U.S. commander and a revised U.S. strategy began to pay dividends.
"Slowly, but inexorably, the tide began to turn," Gates said. Our enemies took a fearsome beating they will not soon forget. Fortified by our own people and renewed commitment, the soldiers of Iraq found new courage and confidence. And the people of Iraq, resilient and emboldened, rose up to take back their country."
In his remarks, Petraeus thanked his troops and hailed Odierno as "the perfect man for the job."
This is the 3rd Iraq tour for Odierno, who told the gathering that while much remains for the U.S. military to accomplish here, the Iraqis must take charge. "This struggle is theirs to win," he said.
Also in attendance for the ceremony were dozens of Iraqi government officials and senior military officers, including Adm. Mike Mullen, chairman of the Joint Chiefs of Staff.
Petraeus' next assignment will be as commander of U.S. Central Command, with broader responsibilities. From his headquarters in Tampa, Fla., he will oversee U.S. military involvement across the Middle East, including Iraq, as well as Afghanistan, Pakistan and other Central Asian nations. He takes up that post in late October.
Petraeus and other military leaders regularly warn that security gains in Iraq are reversible and need continued U.S. attention - a point underscored by persistent bombings that bear the hallmarks of Sunni insurgents.
A bicycle laden with explosives killed two civilians and wounded 19 people at a market north of Baghdad on Tuesday, Iraqi officials said.
The bicycle was left near an Iraqi military truck parked at the main market in Taji, 12 miles north of Baghdad, according to a police officer who spoke on condition of anonymity because he was not authorized to speak to the media.
On Monday, Lt. Gen. Lloyd Austin, the No. 2 U.S. commander in Iraq, told reporters it would be a mistake to push the U.S.-trained Iraqi army and police into a leading security role before they are ready.
"I'm not sure that pushing them forward is the right thing that we want to do. We tried that once before and found that that didn't work," Austin told reporters, referring to the pre-2007 U.S. strategy, which focused on handing off security responsibility to the Iraqis quickly while reducing the U.S. presence. That approach faltered before Bush switched strategies and installed Petraeus in Baghdad, replacing Gen. George Casey.
Austin succeeded Odierno in February as the No. 2 U.S. commander in Iraq. Austin told reporters Monday that he does not expect the switch from Petraeus to Odierno to result in much change in focus.
"They certainly have different styles - they are different people," Austin said, adding that Petraeus and Odierno "think alike." Although both will have four-star rank, Odierno will report to Petraeus.
Gates, who recommended Petraeus for the Central Command post and Odierno for the Baghdad job, told reporters Monday that he is confident that Petraeus will get the credit he deserves for his role in reducing violence in Iraq.
"He's played a historic role, there's just no two ways about it," Gates said. "Gen. Petraeus is clearly the hero of the hour."
Petraeus arrived in Baghdad, for his third command assignment of the war, in February 2007. He is departing somewhat earlier than once planned; it had been expected he would stay until at least the end of this year. But when Adm. William Fallon abruptly resigned as commander of Central Command last spring, Gates decided Petraeus was the best choice to fill that spot.
Petraeus commanded the 101st Airborne Division at the outset of the U.S. invasion in March 2003, and he returned in May 2004 to command the organization responsible for training Iraqi security forces.
In his next assignment, Petraeus will face not only the challenge of Iraq but also an array of other problems and potential crises, including the deteriorating security situation in parts of Afghanistan.
In a telephone interview with The Associated Press on Sunday, Petraeus said experience in Iraq shows it will take political and economic progress as well as military action to tackle increased violence in Afghanistan.
"You don't kill or capture your way out of an industrial strength insurgency," he said.