After 18 years, the end of the United States’ Sisyphean war in Afghanistan may be in sight.

American and Taliban negotiators have developed “a draft of the framework that has to be fleshed out before it becomes an agreement,” U.S. special envoy to Afghanistan Zalmay Khalilzad told The New York Times, and they feel “enough confidence” to forge ahead in sorting out the details.

The basic framework Khalilzad described trades withdrawal of U.S. troops from Afghanistan for the Taliban’s pledge, “to our satisfaction, to do what is necessary that would prevent Afghanistan from ever becoming a platform for international terrorist groups or individuals.” An American exit will also hinge on eventual inclusion of the Afghan government in the talks, as well as Taliban consent to a long-term cease-fire.

So the longest conflict in U.S. history finally may be drawing to a close, and it should come as no surprise that diplomacy is the avenue to its completion. The past two decades have made nothing so inescapably clear as the impossibility of a military solution, as invasion, occupation and nation building have thoroughly failed in Afghanistan.

That is not for lack of trying. The story of Washington’s stagnation in Afghanistan is not a tale of passivity, but recklessness and futility.

This war has cost tens of thousands of American and Afghan lives and trillions of U.S. tax dollars — all of it borrowed, much of it lost or wasted. Yet, Afghanistan today remains in turmoil, with anemic institutions of governance and civil society, ongoing violence, a seemingly permanent refugee crisis, and a robust Taliban presence in (if not outright control of) large portions of the country.

The problem is not that we did too little in Afghanistan; it is that we did too much of the wrong thing at too high a price, for too long, in doomed anticipation of unachievable results. The war in Afghanistan is a “debacle of epic proportions” — as military historian Col. Andrew Bacevich (ret.) wrote last month — for which “stalemate” is too kind a term.

Khalilzad’s announcement is a significant, if preliminary, vindication of a more realistic approach. Though this administration did not initiate U.S. negotiations with the Taliban — they began about a decade ago and have continued on an intermittent, often secretive basis in the years since — President Donald Trump’s impulse to “get the hell out” of Afghanistan and his affection for deal-making have here combined to necessary and overdue effect. The appointment of Khalilzad as the United States’ special representative for Afghanistan reconciliation last year seems to have been something of a turning point, and the challenge now will be to press forward on the basis of this week’s unprecedented progress, despite probable setbacks and the counterweight of inertia from Washington’s bipartisan foreign policy establishment.

While all Khalilzad’s negotiations deserve cheer and support, the administration would do well to remain focused on the higher-priority goal of an American exit from Afghanistan. Ideally, that exit would be accompanied by the conditions Khalilzad named: the Taliban’s rejection and policing of terrorist activity in Afghan territory, a durable cease-fire, and U.S.-facilitated intra-Afghan talks.

Still, if none of that happens — if discussions break down and the present progress is undone — the imperative of an American exit remains.

The last 18 years have demonstrated that prolonging U.S. occupation will not help Afghanistan move toward peace, let alone Western-style prosperity and democratic governance. We will not fight our way to remaking Afghanistan in the American image. And continued U.S. prosecution of this oft-forgotten war will not benefit Americans, either.

“Substantive U.S. interests [in Afghanistan] have never been other than marginal,” Bacevich noted. “In any logical ranking of U.S. strategic priorities, Afghanistan comes nowhere close to justifying the trillion-plus dollars that the United States has spent there since it first intervened.”

That will still be true even if these hopeful talks with the Taliban ultimately fail. It will still be time to stop reprising 18 years of strategic miscalculation and unrealistic expectations. It will still be time for U.S. troops to come home.

Bonnie Kristian is a fellow at Defense Priorities and weekend editor at The Week.