THE OBAMA administration’s relations with Afghan President Hamid Karzai have entered another rough patch, only a few weeks after President Obama appeared to have a successful meeting with the Afghan leader in Washington. A sensitive bilateral agreement on turning over a prison filled with Taliban detainees to full Afghan control appears in danger of unraveling. On Sunday, Mr. Karzai embarrassed visiting Defense Secretary Chuck Hagel by declaring that Taliban attacks during his visit had been carried out “to serve the United States” and “pave the way for foreigners not to leave but to stay.”

This is hardly the first time that Mr. Karzai has been at odds with his allies and, as in past instances, his claims are not as inexplicable as they sound to Americans. The Obama administration, after all, has negotiated with the Taliban without Mr. Karzai’s involvement, though officials say that has not happened recently.

Still, if the latest dust-up is to serve some useful purpose, it should be to remind Afghanistan’s allies that Mr. Karzai’s time in office is winding down — and how and by whom he is replaced is critical to both his nation’s future and to its relations with the United States. To his credit, Mr. Karzai has pledged that he will not be a candidate in the presidential election he has scheduled for April 5, 2014. If that election is competitive and free, the Obama administration could find itself with a new partner with a democratic mandate as it completes the withdrawal of U.S. combat forces and looks forward to the “strategic partnership” it has pledged with Afghanistan in the decade after 2014.

There’s a reasonable shot at holding such an election. A number of potentially strong candidates to succeed Mr. Karzai are emerging, such as former interior minister Hanif Atmarand former candidate Abdullah Abdullah. But the political transition from Mr. Karzai, the only leader Afghanistan has known since the Taliban regime was overthrown, also has the potential to go disastrously wrong. Some analysts believe the president will attempt to promote a relative or a crony as his successor, or that local officials will resort to the ballot box-stuffing that tainted the last presidential election in 2009. A bad election would weaken the Afghan government at a critical juncture and increase the chances that the U.S. departure would trigger a new civil war.

That’s why the United States, the United Nations and NATO ought to begun focusing now on the upcoming election. Rather than chase the distant prospect of a negotiated settlement with the Taliban, the Obama administration and other Western governments ought to press Mr. Karzai to appoint qualified officials to the election commission and allow for international observers, quietly encourage qualified candidates to jump into the race and make plans to protect voters from Taliban attacks.

Little more than a year from now, visiting U.S. dignitaries will no longer have to face Mr. Karzai. What’s needed is a strategy to maximize the chance that his successor will be a competent manager and reliable ally.