President Obama, with Defense Secretary Ashton B. Carter behind him, announced that the United States will leave 8,400 U.S. troops in Afghanistan at the end of his term. (Michael Reynolds/European Pressphoto Agency)

HAVING CAMPAIGNED for reelection four years ago on the boast that “the tide of war is receding” for the United States, President Obama on Wednesday made a final concession to the reality that the tide rolled back during his second term. Mr. Obama once aspired to withdraw all but a handful of U.S. troops from Afghanistan by January 2017; instead, he announced that his legacy would be a force of 8,400 — up from the 5,500 he decided to keep in the fall. The shift of position came at the urging of the Pentagon and U.S. NATO allies, who said conditions in Afghanistan, including disturbing gains by the Taliban, did not justify a further drawdown. Mr. Obama deserves credit for accepting their advice rather than clinging to his wished-for legacy.

The troop extension will have three crucial consequences, as Mr. Obama explained in a statement. First, U.S. forces will be able to continue stiffening the resistance of the Afghan army to the Taliban, which during the past year gained territory in several parts of the country while inflicting heavy casualties on government troops. Two key bases manned by U.S. forces in the east and the south of the country will remain open. The U.S. pledge also will open the way for a NATO-led coalition of 41 countries to extend military commitments that provide another 6,000 troops; at a NATO summit in Warsaw this week, the allies are expected to commit to funding the Afghan army through the end of the decade.

At best, the decisions could force acknowledgment by the Taliban that, as Mr. Obama put it, “the only way to end this conflict and achieve a full drawdown of foreign forces from Afghanistan is through a lasting political settlement” with the government. In the past, Mr. Obama’s public commitments to timetables for U.S. withdrawal probably encouraged Taliban leaders to wait out the United States in the hope that the Kabul government would subsequently crumble. Now, with the new U.S. and NATO commitments, President Ashraf Ghani may finally be able to gain traction in his persistent attempts to jump-start a peace process.

Finally, Mr. Obama’s move should allow his successor to inherit a relatively stable military situation and make his or her own decisions about future U.S. engagement in Afghanistan. On that point, both major candidates have gaps: Hillary Clinton has said little about Afghanistan and nothing about future troop deployments, while Donald Trump has been characteristically self-contradictory. Both should be pressed between now and November to say whether they are prepared to extend the U.S. military presence once they take office.

For now, Mr. Obama has done the minimum to ensure that 15 years of U.S. investment and sacrifices in Afghanistan, including 2,300 military deaths, do not end in catastrophe during his presidency. His successor would do well to learn both from this president’s mistakes — including his attempt to end the war on an arbitrary timetable — and from his political courage in correcting them.