President Donald Trump is right that it’s time for the US to end its longest war. He needs to stop making this harder.

The president cancelled at the weekend a summit at Camp David with Afghan and Taliban leaders that was meant to finalise a peace deal. He had little choice. The decision followed an attack in Kabul that killed a US soldier. Welcoming Taliban officials to the US just a few days later would have been wrong.

The mistake wasn’t cancelling the meeting — it was summoning it in the first place. The purpose wasn’t to move along the talks. Taliban officials said they had no intention of meeting Afghan leaders or amending the draft agreement, which reportedly trades a withdrawal of US troops for Taliban commitments to stop Afghanistan from being used as a terrorist base.

The planned event was mainly to afford the president a photo opportunity. As this scheme fell apart, the abrupt departure of Trump’s third national security adviser, John Bolton, compounded the impression of disarray. Not for the first time, Trump’s theatrics backfired.

A deal along the lines envisioned still makes sense. Refusing to deal with the Taliban and leaving the bulk of US troops in Afghanistan indefinitely isn’t an option. There are too few troops to roll back Taliban gains, and their presence keeps the insurgents fighting. Dragging out hostilities would ensure instability and the deaths of thousands more Afghan civilians.

The withdrawal process needs to resume. As before, the challenge is to prevent Afghanistan from falling back into civil war and becoming a terrorist haven. So in any final agreement, the US must keep as much leverage as possible for as long as possible. That means planning the departure of troops not by the US political calendar — the draft deal apparently aimed for full withdrawal by the end of 2020 — but by concrete actions. The last US troops should leave only when a new and agreed upon political order has begun to take shape.

Meanwhile, the US should do what it can to hedge against Taliban backsliding. This means supporting the Afghan government with money and technical assistance, and emphasising that international aid will vanish if the Taliban seize power violently.

The US must press Afghanistan’s neighbours to work for stability rather than promoting their proxies’ interests. And US forces should develop their capacity to gather intelligence and strike targets even after a full withdrawal, to prevent a resurgence of al-Qaeda and Islamic State.

If the US demonstrates its calm commitment to this approach, it might succeed. Nothing else is likely to. And the president’s best bet, if he wants his policy to work, is to stay on the sidelines.

• Editorials are written by the Bloomberg Opinion editorial board.