If Donald Trump has his way a “peace agreement” in Afghanistan will be finalised in the coming days. It’s a sure bet the US president will claim noisy, personal credit for ending one of America’s longest wars. Knowing him, he may even hail it as the “deal of the century” – despite having already accorded that boastful accolade to his failed North Korea summitry. But the world, as always, should beware a Trump bearing gifts.

It will deliver what candidate Trump most wants – a path home for 14,000 American troops before next year’s US election

What is in prospect, after months of US-Taliban talks, is more accurately termed a troop withdrawal than a peace deal. It will deliver what candidate Trump most wants – a path home for 14,000 American troops before next year’s US election. It will not serve the interests of the Afghan people. More likely, this shoddy stitch-up will leave them trapped inside a pitiless conflict that has claimed tens of thousands of civilian lives since 2001.

Right now, it’s as bad as ever. July was the most lethal month for years, with about 1,500 people killed or wounded. And a chilling glimpse of worse to come emerged at the weekend when more than 60 wedding guests were killed by a suicide bomber in Kabul. A series of attacks in Jalalabad followed on Monday.

It’s well known that Trump never supported the US’s Afghan involvement, criticising its cost (financial, not human) and characterising it, unfairly, as another Obama bungle. For him, nation-building, like altruism in any form, is a foreign concept. Yet his reckless push to leave, without adequate security guarantees and a credible plan, is betrayal on many fronts.

First and foremost it betrays the painful, patient efforts of ordinary Afghans to build a more inclusive, tolerant society after decades of civil war and external meddling. It betrays a fragile democratic process, whose next stage – presidential elections next month – is jeopardised by uncertainty over US intentions. And Trump’s unprincipled cut-and-run betrays Afghan women’s groups and civil society activists whose precious gains, in terms of personal freedoms, education, healthcare and travel, may be trampled in the rush for the exit. If the Taliban regain the upper hand religious and ethnic minorities, such as the Shia Hazaras, will suffer badly.

The abandoning of Afghanistan is a gross betrayal, too, of the sacrifices made by American and Nato military personnel, who were told that they were fighting the good fight. More than 2,300 US military personnel have died in Afghanistan. More than 20,000 have been wounded.

And what of the terrible price paid by the UK’s troops? At least 450 died in support of Operation Enduring Freedom. Many more were maimed for life. Yet this operation has neither endured nor secured freedom – and Helmand, scene of bitter fighting involving British forces, is back in insurgent hands. Gallingly, the Taliban now control, or contest, more territory than at any point since 2001 when George W Bush and Tony Blair went after Osama bin Laden and al-Qaida following the 9/11 attacks. And yet here is Trump, the well-heeled Vietnam draft-dodger, walking away on two good legs and looking to cash in electorally. Where is the anger, where is the fury, at this cruellest, most cynical of betrayals?

The outlines of the deal being discussed in Qatar are fairly clear. In return for safe passage for departing forces and a Taliban pledge not to provide safe haven to jihadist groups such as Isis, Trump will end the US’s campaign and bring its troops home. But crucial questions are up in the air. The Afghan government in Kabul, excluded from the Doha process, is expected, somehow, to reach a power-sharing arrangement with the Taliban. So far, neither side shows any sign it is able or willing to do so, not least because of intra-Afghan political splits and mutual, deeply ingrained enmity.

For this reconciliation process even to begin, there must first be a nationwide ceasefire between the Afghan army and the insurgents. But the Taliban expressly reject any truce until all foreign forces have left – their fundamental demand. Meanwhile, al-Qaida and a strengthening Isis can be expected to do their brutal best to disrupt any progress.

The US military and intelligence agencies are by no means united in their view of Trump’s bid to portray retreat as victory, either. Experienced commanders such as the former US general David Petraeus doubt a divided Taliban leadership will keep its word. Hard-line elements may reject a deal of any kind. So it makes sense that the US keep a residual force, primarily tasked with counter-terrorism but also with supporting the Afghan government and army. “A complete military exit would be even more ill-advised and risky than Obama’s disengagement from Iraq in 2011 [which opened the way for Isis],” Petraeus warned this month.

A gradualist approach also reduces the risk that Iran, Russia, Pakistan and India – traditional players in the “Great Game” – will exploit the vacuum caused by a precipitous US exit, thereby once more turning Afghanistan into a regional battleground and transforming a historic defeat for the west into an ongoing strategic disaster. Wars in Afghanistan do not end well. When a British army retreated from Kabul in 1842, during the first Anglo-Afghan war, it was ruthlessly annihilated at Gandamak on the road to Jalalabad.

No right thinking person would wish Gen William Elphinstone’s sorry fate on the departing Americans. But Trump must understand that if the US is to leave peacefully, it must do so responsibly and by stages, and in a way that ensures the hard-won political and social gains of recent years are not wantonly squandered. Afghanistan was broken. We in the west promised to fix it. Like it or not, that promise must be honoured.

• Simon Tisdall is a foreign affairs commentator