Yesterday General David Petraeus handed over the flag of his command, known as the Multi-National Force in Iraq, to General Raymond Odierno. The ceremony, held at the U.S. military headquarters at Camp Victory on the western outskirts of Baghdad, was moving and memorable. Graced by the presence of Secretary of Defense Robert Gates, it marked the completion of one of the most remarkable military tenures in American history. As Secretary Gates said, “He's played a historic role…General Petraeus is clearly the hero of the hour.”

When General Petraeus took command in Iraq in February 2007, it was in a death spiral, teetering on the brink of a full-scale civil war. Petraeus faced the toughest situation he had encountered in more than three decades of military service, a situation that many analysts thought was hopeless.

In 19 months, General Petraeus achieved the closest thing to a battlefield miracle you are likely to witness in your lifetime. He certainly didn't do this alone; we have fielded as fine a fighting force as the world has ever seen, and he has had many able men at his side, including General Odierno. But General Petraeus is the individual who led the effort, who rallied our side, who pushed back against those in the chain of command who opposed his efforts, and who successfully implemented the new counterinsurgency strategy. The U.S. military took on the role of “builders and diplomats, as well as guardians and warriors,” according to Petraeus.

In Secretary Gates's words, under the leadership of Petraeus

Slowly, but inexorably, the tide began to turn. 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.

American combat forces are by and large already out of the populated areas in 13 of Iraq's 18 provinces. Eleven provinces have already been transferred to Iraqi control, with two more expected to shift in October. Violence has dropped a staggering amount, to levels not seen since early 2004. Attacks have plummeted from a daily rate of 180 in June 2007 to about 25 today. According to Petraeus, the number of attacks in Baghdad, a city of seven million, averages probably less than five a day.

In Petraeus's words, Iraq is a “dramatically changed country” from what it was early last year. “There is certainly a degree of hope that was not present 19 months ago,” he says. Petraeus once described Iraq as “hard but not hopeless.” Today he says Iraq is “hard but hopeful.”

In assessing where things stand, Petraeus remains properly cautious. There remain storm clouds on the horizon and challenges, including integrating the Sons of Iraq into the Iraqi army, resolving the final status of oil-rich Kirkuk, key provincial elections, and remaining ethno-sectarian tensions. Al Qaeda in Iraq, while having absorbed massive blows, is still lethal. Iraq remains the central front for al Qaeda and global jihadists, according to Petraeus. And the Iranian-backed “special groups” militias have fled Iraq to Iran, Lebanon, and Syria, where they are taking a wait-and-see attitude. Iraq, then, is still a battered and in many respects a broken nation. But before it was on the brink, and now it is on the mend.

In October, Petraeus will head to Tampa to take over Central Command, where he will oversee U.S. operations in the Middle East, Central Asia, and the Horn of Africa. At the top of his to-do list will be Afghanistan, where the trends are heading in the wrong direction. As Petraeus has said, “There are limitations in Afghanistan that are not found [in Iraq]…Iraq's infrastructure is still vastly greater than that of Afghanistan. So, there was an ability [in Iraq] to absorb a substantial number of forces in a relatively short period of time.”

The challenges in Afghanistan, then, are quite different from those Petraeus faced in Iraq. But there is probably no one on the planet better equipped to reverse the trajectory of events in Afghanistan. And if he does, it will only add to his reputation as one of the finest military minds and most important military figures in American history. What David Petraeus achieved in 19 months in Iraq was that impressive, and that important.

— Peter Wehner is a senior fellow at the Ethics and Public Policy Center in  Washington, D.C. He served in the Bush White House as director of the office of strategic initiatives.