The news that General David Petraeus will replace Stanley McChrystal as the commanding general in Afghanistan is a brilliant stroke by President Obama. He gets all of the benefit of relieving General McChrystal — a patriot and a hero who had a terrible lapse in judgment — and none of the drawbacks. Obama is replacing an outstanding general with one of the best in our history.

General Petraeus is the man who, more than any other single individual, turned around the war in Iraq. It was a nation on the brink of civil war when he was named commanding general there — and today it is a nation on the mend. That is the result of many hands and many hearts — but no single individual is more responsible for what happened in Iraq than Petraeus. In addition, General Petraeus literally wrote the book on counterinsurgency, having authored the Army's manual on the subject. Petraeus, then, is both the intellectual architect of our COIN strategy and its best practitioner.

Beyond that, Petraeus — like McChrystal before him — has the confidence of President Karzai, which U.S. Ambassador to Afghanistan Karl Eikenberry and National Security Adviser Jim Jones (among others) do not. He understands, unlike others in the Obama White House, that the way to deal with someone like Karzai is to support him in public and make demands of him in private. Nouri al-Maliki was no walk on the beach, either; but Petraeus, along with Ambassador Ryan Crocker, dealt with him extremely skillfully, holding him close while moving him along the right path.

What is also significant is that Petraeus has the confidence of our troops because of what he has achieved. He is not only a respected figure; he is very nearly legendary among them. The troops in Afghanistan will treat him as college basketball players would treat Mike Krzyzewski, if he took over another basketball program. There is instant trust, instant credibility, and instant confidence. And that matters.

As for the war Petraeus now oversees: it is not going easily, and in some respects, it is not going well. But it is not going as badly as some commentators assert. Military commanders believe that at long last they have the inputs right, after months of enormous work and effort. We are only now beginning to execute the COIN strategy. Predictably, just as it happened in Iraq, the enemy is fighting back. We have always known Kandahar was going to take months, and we are actually slightly ahead of schedule in the deployment of additional troops and their equipment. As Max Boot points out, there are a number of things working in our favor in Afghanistan. Petraeus said in a recent Congressional testimony that despite the tough losses and despite the setbacks, the trajectory has generally been upward. If defining winning as making progress, Petraeus said, “then I think we are winning in Afghanistan. It is a roller coaster ride, however.” It is surely that, and it requires people to fasten their seatbelts and not panic when success isn't instant. As Petraeus's former sidekick in Iraq, Ambassador Crocker, used to say, “It's all hard, and it's hard all the time.”

What Petraeus also needs, apart from time, is the full support of the president and his team. Petraeus had that in Iraq with President Bush. There were no efforts by then-Chief of Staff Josh Bolten to go on Sunday-morning talk shows to interpret troop-withdrawal timelines one way while Petraeus interpreted them another. The Vice President was not actively attempting to undermine what Petraeus was doing in Iraq. Late in the day, the Bush administration, after costly mistakes, decided on the surge strategy and united behind it. Despite enormous political pressure to pull back, Bush gave Petraeus the time and the tools he needed. It was a remarkable demonstration of presidential courage and wisdom.

Right now President Obama is overseeing a terribly dysfunctional process. Ambassador Eikenberry and General McChrystal were at odds. James Jones often comes across as inept. There still seems to be no consensus on whether the self-imposed deadline for troop withdrawals is conditions-based or not. Indeed, political advisers have been helping to determine the strategy in Afghanistan. In a somewhat stunning story in the Washington Post, we read this:

In exchange for approving McChrystal's request for more troops and treasure, Obama imposed, and the military accepted, two deadlines sought by his political aides. In December, one year after the strategy was announced, the situation would be reviewed and necessary adjustments made. In July 2011, the troops would begin to come home. Each side thought it had gotten the better part of the deal. Many senior military officials considered the withdrawal deadline a bad idea and argued among themselves whether counterinsurgency, inherently a time-consuming roller coaster of a process, could be conducted on a clock.

This infighting needs to come to an end. General Petraeus needs a lot of things in order to succeed — but what he needs most of all is the full support and commitment of the commander in chief. Petraeus, despite his remarkable record of achievement, cannot succeed without it.

On the day Bush met with Petraeus privately in the Oval Office, after the Senate confirmed his selection for a mission that seemed unachievable, Bush said we were doubling down in Iraq. Petraeus said, “Mr. President, this isn't double-down. … This is all-in.”

Barack Obama better be all in. If he is, he has the right man at the helm. If given the tools, David Petraeus — one more time — can finish the job.

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.