Editor's note: Peter Bergen, CNN's national security analyst, is a fellow at the New America Foundation, a Washington-based think tank that promotes innovative thought from across the ideological spectrum, and at New York University's Center on Law and Security. He's the author of "The Osama bin Laden I Know: An Oral History of al Qaeda's Leader."
(CNN) -- He is arguably the most well-known American general since MacArthur, and perhaps the most effective since Eisenhower.
Now Gen. David Petraeus takes on what many believe will be his biggest challenge yet: reversing the momentum of the Taliban in Afghanistan and helping to stabilize the rickety regime of Afghan leader Hamid Karzai.
Petraeus faced far more daunting challenges in Iraq when he assumed command there in early 2007. Those challenges, and how they were overcome, are worth recalling as he assumes command in Afghanistan, as they may provide some indicators of the way forward there.
First, Iraq was embroiled in a vicious civil war in which Shia and Sunni civilians were showing up dead on the streets of Iraq's cities at the rate of 90 a day, some tortured in the most unspeakable manner, their heads drilled open.
Iraq's Ministry of the Interior, which was nominally in charge of the country's security, itself had taken been taken over by Shia death squads.
This was further complicated by the industrial-strength Sunni insurgency led by al Qaeda's vicious Iraqi affiliate. It recruited fighters from around the Middle East, who were largely responsible for an epic campaign of suicide attacks that killed thousands of Iraqis.
Indeed, more suicide attacks were conducted in Iraq between 2003 and 2007 than had taken place in every other country of the world combined since 1981.
The war was so violent that almost five million Iraqis -- around a fifth of the population --fled their homes for the safety of other countries or internal exile. Relatively few of those refugees have since returned.
Despite the widespread perception that Afghanistan is today going to hell in a handbasket, more than five million Afghan refugees have returned home since the fall of the Taliban.
Last year some 2,400 Afghan civilians died in the war -- too many, of course, but in Iraq when Petraeus took command, 3,200 civilians were dying every month, making Iraq around 15 times more violent than Afghanistan is today, when adjusted for relative population size.
And contrary to the old saw that Afghans are virulently opposed to foreign forces on their soil, a BBC/ABC poll taken earlier this year -- almost a decade after the fall of the Taliban -- found that 62 percent of Afghans support international forces in their country. Contrast that with Iraq, where a BBC/ABC poll taken just two years after the U.S.-led invasion found that only one in three Iraqis supported the foreign soldiers in their country.
This is a critical point in Afghanistan, as the center of gravity in a counterinsurgency is the protection of the population itself, a theory of counterinsurgency warfare that Petraeus enshrined in U.S. military doctrine, when he oversaw the work on the unglamorously named Counterinsurgency Field Manual 3-24 in 2006 at the Army's training center at Fort Leavenworth, Kansas.
When the final version of the Counterinsurgency Field Manual was published in December 2006, it was downloaded 1.5 million times within a month of its posting. The New York Times gave it a serious review, something of a first for a dense military tome that weighed in at some 400 pages.
The doctrines in that counterinsurgency manual have driven the subsequent actions of the U.S. military both in Iraq and Afghanistan. The following points from the manual summarize its central message: "Unsuccessful practices: overemphasize killing and capturing the enemy rather than securing and engaging the populace; conduct large-scale operations as the norm and concentrate military forces in large bases for protection."
Successful practices, according to the manual: Focus on the population, its needs, and its security, and provide amnesty and rehabilitation for those willing to support the new government. In a section titled "Paradoxes," the manual made a number of recommendations that were hardly typical of prevailing U.S. military doctrine: "Sometimes doing nothing is the best reaction" and "the host nation doing something tolerably is normally better than U.S. doing it well."
These commonsense prescriptions would, in time, help to change the course of the Iraq War.
Petraeus, an intensely competitive officer with a Ph.D. in international relations from Princeton, assembled a brilliant staff to reassess and redirect the Iraq War. When he arrived in Baghdad, Petraeus brought with him a sense that there was a plan. And he also had the full support of President George W. Bush, with whom he held a weekly private videoconference, which was unprecedented since the president was circumventing several levels in the chain of command to speak to his field commander.
Watching Petraeus's Battlefield Update Assessment, held every morning at "Camp Victory" in Baghdad, was to see a master at work, cajoling and cheerleading his commanders across the country via video link as they reported on every variable of the Iraqi body politic from the grandest of political issues to the minutest of water projects.
The new team and new approach got American soldiers out of their bases and into the neighborhoods. It was amplified by the arrival of what would eventually become the 30,000 soldiers of the "surge" authorized by Bush as Petraeus took command in Iraq.
Petraeus outlined his "population-centric" strategy in a three-page letter he distributed to all of the soldiers under his command. "You can't commute to this fight. ... Living among the people is essential to securing them and defeating the insurgents. ... [P]atrol on foot and engage the population. Situational awareness can only be guaranteed by interacting with people face-to-face, not separated by ballistic glass."
There were also shifting dynamics on the ground in Iraq that would make the additional combat brigades of the surge a force multiplier rather than simply more cannon fodder for Iraq's insurgents. Those changes included:
• The rise of the "Awakening" movements -- former Sunni insurgents who signed up for security jobs paid for by the U.S. military.
• Previous sectarian cleansing that forced millions of Iraqis to flee their homes, and which made it harder for the death squads to find their victims. In Baghdad, half the Sunni population had fled the city by the end of 2006.
• Around the same time, efforts to register all military-age Iraqi males using biometrics such as retina scans, which created a useful database of that population.
• Walls built around vulnerable neighborhoods that kept insurgents out.
• Better bomb detection devices, such as drones equipped to spot subtle anomalies in roads indicating the presence of bombs; the increasing deployment of hulking armored vehicles with V-shaped hulls known as MRAPs, which are largely immune from roadside bombs; and an aggressive effort to map and target the networks of Iraq's bomb makers. All these things led to a decline in the number of deaths caused by the leading killer of U.S. soldiers -- the improvised explosive device. The number of IED attacks in Iraq dropped from almost 5,000 in 2006 to around 3,000 two years later.
The PowerPoint briefing slides so beloved of the U.S. military showed the violence in Iraq peaking in almost every category in the first months of 2007 and steadily dropping after that. That decline was true across the board, including attacks by insurgents, civilian deaths, U.S. soldiers killed, Iraq security forces killed, car-bomb attacks, and IED explosions. The number of Iraqi civilians dying in sectarian violence began a sharp decline from its high of around 90 every day in December 2006, to single digits two years later.
Can Petraeus and his team pull off something similar in Afghanistan?
The strategy that Petraeus will pursue there will not differ in any substantial way from that pursued by outgoing Gen. Stanley McChrystal. After all, Petraeus is the principal theorist and practitioner of counterinsurgency in the U.S. military and was one of the small group of Pentagon leaders who pushed for McChrystal to be installed as the commander in Afghanistan a year ago.
As Petraeus himself has sometimes said, Afghanistan could be harder than Iraq. And indeed it may be, for while the country is certainly not in the grip of a full-blown civil war as Iraq was in early 2007, it is still reeling from the effects of more than three decades of war.
Also, the Taliban in Afghanistan are not a bunch of foreigners with foreign ideas as al Qaeda was in Iraq. In the rural Pashtun South of Afghanistan, the Taliban are the guys you grew up with and are much savvier about how to win, if not the support, at least the acquiescence of a sizable part of the population.
The insurgents in Iraq had nothing on the scale of Pakistan's tribal regions as a safe haven, as the Taliban do now, nor did they have the world's largest supply of opium and heroin to help finance their insurgency.
In Iraq, Petraeus helped stanch a terrible bloodbath and bring the country up to the level where it is a state perpetually on the edge of conflict between Kurds and Arabs or between Shias and Sunnis, but it has at least achieved some kind of tenuous peace.
In Afghanistan, Petraeus must convince all sorts of constituencies, from the Afghan people, to the Pakistani military and political establishment, to the White House, to the American public, that some plausible progress is being made; that the Americans are not going to "cut and run" before a semi-stable Afghan government and military are in place. And he must do that all on a timetable in which some kind of American drawdown begins in July 2011.
It's as big a challenge as plugging the BP oil spill, and to do it right might take as long as reversing the environmental catastrophe that is already in progress in the Gulf -- a very long time, measured more in decades than in years.
No one is better equipped to handle the challenge than Gen. David Petraeus. But as a student of history, the general is surely aware that what worked on the banks of the Tigris and Euphrates in 2007 could still crash on the shoals of reality on the banks of the Kabul and Helmand rivers several years later.
As the philosopher pointed out: You can't step twice into the same river. Not even someone as talented as David Petraeus.
The opinions expressed in this commentary are solely those of Peter Bergen.