Interviewed on Meet the Press last weekend, John Kerry never wavered: Invited to say he was impressed by the turnout in Iraq's election, he declined, saying that it had been merely "as expected." By whom? Was anybody else as optimistic last week as Kerry says he was? Most people had been dreading—or, depending on where they stood, contentedly expecting—an election where nobody showed up. Unlike the junior senator from Massachusetts, most of the world was surprised that so many Iraqis defied the country's murderous insurgents and stood proudly in line to cast their votes.

Good news in Iraq is rare these days. So much has turned bad that even the White House is no longer arguing that things have gone according to plan. Some of what went wrong was always going to, because the task America and its partners took on was so difficult. A lot of the mess, on the other hand, could have been avoided: Negligence and incompetence are to blame for much of it. Nonetheless, the election shows that despite all the errors, forced and unforced, not everything has gone wrong—and that a great prize is still at stake.

The occupation is unpopular with many Iraqis, and not just with the minority Sunnis: The terrible violence on the streets and the toll taken on the country's economic infrastructure have left many people feeling worse off than before the war. But the election shows that it is wrong to think that Iraqis have no real appetite for democracy, or to think that the effort spent on moving the country toward it is futile—mere public relations, undertaken at enormous cost to Iraq and America alike. On the contrary, the freedom to cast a vote, even in such a flawed election—and it certainly was flawed—obviously meant a lot to most Iraqis. This was good to see, inspiring even. It is surely a hopeful sign.

Looking ahead, though, does it make the task of America and its partners any easier? Aside from this week's lifting of the spirits—and, depending on what the insurgents do next, that may not last long—the answer is no. If the United States does the right thing, it will find no fast, easy exit from Iraq. Election Day was a success, to be sure, but it has not altered that depressing reality.

For a moment after America's victory over Saddam Hussein in 2003, as Iraqis celebrated the regime's downfall, it was possible to think that forthcoming elections would consummate the nation building that the United States had undertaken. There would be some necessary delay: a period of rule by viceroy in all but name, then partial, nondemocratic rule by Iraqis. But these transitional arrangements would be followed shortly by elections, and Iraq would be a sovereign nation again, and a democracy too.

Today, it is unclear whether a democratic Iraq can ever be a nation. At the moment, if not for the presence of American forces, Iraq would be facing an outright civil war between the majority Shiites, suppressed by the old regime, and the minority Sunnis, fighting to restore their powers and privileges. This is to say nothing of Iraq's other big minority, the Kurds, many of whom want full independence.

Eventually, some sort of loose confederation may be the only way to rule the country. But even if these groups might one day live comfortably under a single polity, America will not have built a nation in Iraq until the country is properly governable—that is, until a legitimate government has a monopoly on the use of force and all Iraqis enjoy a minimum standard of physical security. Elections are a step forward in that regard. They move the government closer to legitimacy. But they do little or nothing to move the country closer to security.

In his interview, Kerry said that the election (the Iraqi election, that is) was only "kind of" legitimate. On that, he was correct. True, it is the insurgents' fault and that of the Sunni political leaders, not the fault of America and its allies, that the election failed to draw in all Iraqis. But when it comes to judging the vote's perceived legitimacy, where the fault lies makes no difference. With Sunnis for whatever reason underrepresented in the polling, the results have no effective claim on their consent or loyalty. And the election was flawed in other ways, too: no campaigning, no engagement of competing political ideas. It was not a sham, by any means. Nor was it, unfortunately, an election that confers legitimacy in the way that is taken for granted in the West.

In any case, no election, legitimate or otherwise, could by itself release America and its allies from their continuing responsibility to the Iraqi people. This was a war of choice, and dealing with its aftermath falls to those who made that choice: America and its partners. For Iraq to regain meaningful nationhood, the insurgency must be defeated—or, at a minimum, the security forces of a lawful and tolerably democratic Iraqi government must be competent to contain it without help from the outside. Given the mistaken decision to disband Iraq's army rather than to decapitate and reform it, getting there could take a long time. Training an effective local security force is proving to be slow work.

If, in the meantime, Iraq's leaders call on America and its allies to leave, then of course they should. The coalition must remain only at the invitation of Iraq's majority. For as long as that invitation stands, however, America and its allies are under an obligation to stay, quite possibly in greater numbers than at present, until the country has a government capable of governing.

If the election, partly because of its democratic defects, has failed to relieve America of its new burden, was it right to hold the vote in the first place? You might argue that it would have been better to delay until the vote could have served not only to choose a government but also to signal the country's democratic graduation and the end of outside involvement. If all of that could have been done quickly, it would have been an attractive option. Clearly, however, it is not going to be done quickly. Delaying the vote until the country was stable, so that the election could have prompted the withdrawal of American forces, might have meant foreign and/or patently undemocratic rule for another year, or two years, or longer. Almost all Iraqis would have found intolerable an occupation perceived to have no intention of winding itself down.

Better to do what has been done—hold early elections that are not the end of the process, just one step forward. The important thing now is for the administration and its friends, in particular Britain's Tony Blair, to understand the implications of that choice. They must resist growing pressure to announce an exit strategy in the form of timetables for troop withdrawals.

To draw down forces under cover of the elections is tempting. It would disarm many of the governments' domestic critics, who are calling for it; it would limit the huge and mounting costs of a continuing military commitment; and it might lessen the zeal of America's enemies elsewhere in the Middle East, who find America's operations in Iraq an energizing provocation. Even so, on balance it would be a mistake.

If America's goals in Iraq—stability, self-government, and democracy—were beyond reach, the White House would be right to start planning a troop withdrawal, and this might just as well be sooner rather than later. It would be better for America to cut its losses than struggle on pointlessly, and the eventual outcome for Iraqis would be just as dismal in any case. In the end, things could come to that. But not yet: Those goals are still achievable. The Iraqis' appetite for democracy suggests that the United States can still redeem its misadventure in Iraq, despite all the administration's mistakes, including its rationale for waging war in the first place. A stable democratic Iraq would be worth the heavy price that America has paid since it decided to invade, and is yet to pay.

Getting there will require American resources and resolve. Unfortunately, that is not all it will require. Iraq's Shiites, having asserted their desire for democracy in the face of a savage anti-democratic insurgency, must now be willing to compromise. The next step is to devise a constitution that shares power equitably rather than entrenching a new tyranny, this time of the majority. That will call for restraint and moderation of a sort that Iraq has not experienced. America can urge these things on the country's emerging politicians. If they choose otherwise, there is little it can do. That is why, whatever its own choices, America may fail in Iraq. But it is too soon yet to admit defeat.