Three years ago, the war in Iraq seemed lost.

There was little disagreement that the Bush administration, having toppled Saddam Hussein with relative ease, had badly bungled the aftermath. Tank units led by Gen. Tommy Franks had led U.S. forces triumphantly into Baghdad. There had been a ceremonial toppling of Hussein's statue, and the presidential "Mission Accomplished" news conference . . . and then the real war started.

It was a mistake seemingly made in every war in human history; commanders enter superbly prepared to fight the last war, not the one they are in. It turned out that the war in Iraq was not about seizing territory but battling a stubborn, murderous, and determined insurgency embedded in the Iraqi population.

President Bush made a courageous decision in the summer of 2006 to reverse direction, but not the reversal sought by Congress (including then-Sens. Barack Obama and Joe Biden), the American public, the overwhelming majority of the press (including this newspaper), and even most of his own military advisers. Instead of cutting our losses and pulling out of Iraq, as we did in Vietnam, Bush doubled down. He invested more troops and, more important, embraced an entirely new strategy.

And Bush was right. What had happened beneath all of the politics was a small revolution in war-fighting philosophy, championed and implemented by an unlikely military leader, Gen. David Petraeus, a soldier/intellectual molded as much by the think tank as the battlefield. He calls the movement his "Counterinsurgency Nation," and it has rewritten the way America fights. It is not a completely new idea - there are few of those in the study of war - but its basic principles came into clearer and clearer focus as a new generation of military officers fought in Afghanistan and Iraq. Its guiding principle is simple: The prize in these countries is not territory, but people.

Now President Obama must decide whether to let this new generation of battle-tested soldiers apply what it has learned to Afghanistan. Those who argue that the methods employed in Iraq will not work in Afghanistan are right and wrong. They are right that the two conflicts are not identical. What worked in Iraq will not apply in all cases in Afghanistan. But they are wrong to assume the lessons of Iraq have no application in Afghanistan. The counterinsurgency consensus grew out of experience in both wars. America's new military leaders have been managing both conflicts simultaneously for most of this decade, and the hard-won lessons they have learned derive from both.

I am not a military expert, but I suspect that most wars that last for more than a few weeks follow a roughly similar trajectory. Established generals misjudge the war, and once the battle is joined, a generation of younger leaders discovers the truth, adapts by hard necessity, making life-and-death decisions on the battlefield, and learns, often by trial and error, how to define and fight the new war on its own terms. If the national leadership is smart enough to embrace this knowledge and experience, as Bush was, the tide turns.

There are a number of excellent studies that document this turnabout, notably Thomas Ricks' The Gamble, Linda Robinson's Tell Me How This Ends, and Kimberly Kagan's The Surge. The Iraq war is not over, of course. It remains to be seen if Iraqis can forge a nation from its various contending factions, but there is no denying the extraordinary reversal engineered by Bush, Petraeus, and the remarkable soldiers who have risked and all too often sacrificed life and limb for the last six years. They accomplished it amid a persistent chorus of critics and doomsayers - doomed was actually the word then-Sen. Biden used to describe Petraeus' chances in April 2006.

Counterinsurgency doctrine is as warm and fuzzy as war can get. It embraces distinctly liberal, humanistic values like protecting civilians, cultural sensitivity, and rigid adherence to ethical standards and the law. It is geared toward partnership, not dominance, and always seeks to minimize violence. In Iraq it rapidly (in months) isolated the murderous extremists who were trying to provoke civil war. The new effort set up a sharp contrast between their methods and goals and America's. As one Marine officer, Col. Julian Dale Alford, said at a conference in Washington last week: "We gave the people of Iraq a better choice."

But counterinsurgency is not like the "Get out of jail free" card in Monopoly. It demands risk. It means getting soldiers out of the relative safety of large, well-defended bases and impregnable vehicles, and ordering them to live with the people they are tasked to defend. It makes them more vulnerable - the initial impact of the surge in Iraq caused a sharp increase in U.S. casualties - in order to build long-term security. It is a dreadful bargain, courting greater risk in order to lower the violence. It is also counterintuitive. But it works.

Counterinsurgency wars are also long wars. They require a commitment of troops, time, and money over not just months, but years, because success depends on convincing the Afghan or Iraqi people that America is serious about protecting them and will not abandon them. As Gen. Stanley McChrystal's leaked assessment of Afghanistan makes clear, pursuing the war against the resurgent Taliban will require more of everything.

The new strategy also pointedly rejects the approach reportedly championed by Biden, which is to forgo efforts to protect and win the population and concentrate instead on finding and killing extremists, using drones and special forces. Ironically, this was the very approach tried and abandoned by Bush in Iraq. It turns out that an insurgency can be killed only by poisoning the sea in which it swims. You need the people.

Obama's war-fighting promise was to scale down Iraq and ramp up Afghanistan, which he argued was the necessary war. He has the strategy and the men to do just that, thanks in large part to the man who is least likely to be given credit, George W. Bush.