A president can bluster or blunder this country into a world of trouble. That was the tale of most of the past decade. But with skill and judgment, with a nuanced combination of restraint and initiative, Barack Obama has just zigged and zagged his way through a crisis in Egypt in which he successfully secured American interests and ideals.

The 18 days in Tahrir Square now belong to history. Soon enough, what happened behind the scenes in Cairo and Washington will be recounted in some insider-infused first draft. But in an age of impatience, some rushed to conclude that Obama's administration had bungled the crisis or caught up to the revolution a little too late. The truth, like Obama's diplomacy, is more subtle.

In the winter of their discontent, the Egyptians took things into their own hands. Television was in the streets along with Twitter and Facebook and the whole world was watching. But the cameras had been in other places too — from Tiananmen to Tehran not so long ago. This uprising too could have ended in defeat and death. Instead, in carefully modulated fits and starts, the president, the Pentagon, and his national security team facilitated a more democratic dispensation in Egypt while simultaneously achieving the best that was possible for the United States and its allies.

American interests and ideals were well served.

Along the way, Obama took blame that wasn't properly his — on one side, from the non-Kristol neocons who invoked shades of the Ayatollah and the Shah as they insisted that the right choice was to prop up the tottering Mubarak — and on the other side, from human rights activists who demanded that the president immediately pitch Mubarak under the bus.

Both alternatives had the virtue of simplicity. The first also suffered from defects of morality; it was unattainable short of American association with public mass murder. And publicly disdaining Mubarak too early would have had the defect of diplomatic disaster. The president had to preserve American credibility with conservative regimes that are important allies in the region. He couldn't afford to send the message that at the first onset of trouble, the United States would forthwith abandon them.

Speaking softly at the start, and eloquently at the end, Obama leveraged American power to influence the Egyptian armed forces. It's clear that the Egyptian generals, their forces sustained by U.S. foreign aid, themselves regularly engaged in joint planning with the Pentagon, were in repeated conversations with Washington and Secretary of Defense Gates as they opted not to fire on the demonstrators. It doesn't detract from the courageous Egyptians who won their battle armed only with social networks to say that this decision marked the line between triumph and tragedy. Nor does it detract from the demonstrators to conclude that American will, implied and then explicit, played at least a supporting role in sending Mubarak on his way to Sharm el-Sheikh.

Obviously, by the 17th day, Obama had been told the dictator was ready to go; the president all but said so. But stubborn, proud, self-deluded after three decades of absolute rule, Mubarak delivered a rambling speech that seemed to say he was playing for more time.

That Obama had got it wrong was the instant verdict of commentators; see how ineffectual he is, how little influence the U.S. has. The next day Mubarak resigned — or more accurately was resigned by the Egyptian army. It will be fascinating to read the back-story and explore the backstage of this history years or decades from now — sooner if Bob Woodward has his way. But it's inconceivable that the administration wasn't deeply involved — and influential — in the final decision to depose Mubarak.

It may not be fashionable to suggest this — or entirely convenient for a President intent on celebrating the protesters as he focuses on the shape of Egypt's future, and the Middle East's — but Obama understands that diplomacy is not one-dimensional. The conservative regimes in the region surely aren't happy with the result—but by the end, given enough time to see it, they too knew that Mubarak couldn't be propped up at any acceptable cost. Israel isn't happy either — but at the very start of the transition in Egypt, the peace treaty between the two countries has been reaffirmed.

Yes, Obama zig-zagged. Commanding presidents have followed that course before in the face of fateful challenge — Lincoln on the abolition of slavery during the Civil War; FDR on the break with isolationism and American entry into World War II. Both were sure of their objective; both balanced it against the pressures and exigencies of the moment. Neither moved quickly. But both got there.

So it was with this president as the riveting drama unfolded on the Nile. The saga is unfinished there, across the region, and for the United States. But the results so far are not bad. In 18 days, the White House advanced our values, protected our vital interests, and demonstrated the power of America's reach and influence.