In Eric Joyce's noisy letter of resignation as an aide to the defence secretary, the Labour MP wrote that he had chosen this moment to quit because it "seems to me the least disruptive time to do that". This is not at all how it seemed to Gordon Brown who felt very disrupted indeed. The prime minister stomped around Number 10 angrily demanding: "Why wasn't I told? Why wasn't he stopped?" Major Joyce held the insignificant political rank of PPS, but his decision to tear off his stripes resonated because he was previously characterised by his über-loyalty and is unique among Labour MPs in having any recent experience of serving as an army officer. The galloping major's resignation was not the prelude that the prime minister wanted for his supposedly definitive speech on Afghanistan.

It was a speech which tried to explain what success might look like, but was inevitably haunted by the failures that forced him to address the subject. The history of this conflict has been told in terms of triumph and disaster, those twin impostors of Kipling's poetry. Many of the current difficulties flow from the deluded triumphalism of eight years ago when, in the wake of 9/11, the Americans with British help toppled Mohammed Omar's diabolical Taliban regime. The rapidity of that victory appeared to confound all the dire warnings about Afghanistan being a graveyard for foreign armies. One delirious American neocon wrote: "With less than a month to prepare, American troops and aircraft had charged into this country, overthrown its government, destroyed its terrorist bases and hunted down their enemies, while losing only 15 of their own to enemy action." Never had regime change seemed such a piece of cake.

Just as in Iraq, there was scant attention paid to the sequel: the tough, expensive and long-term challenge of conflict resolution and nation building. "We will not walk away," promised Tony Blair before the west did just that. The Germans, having promised to take responsibility for training the Afghan police, sent a grand total of 17 officers to do the job. "US forces will not stay," George Bush declared to a meeting of his National Security Council on the very day that the Taliban fled Kabul. Michael Boyce, the then chief of the British armed forces, did his best to scratch together a Nato peace-keeping force, but it was never adequate for the task and lingered there without clear military or political objectives.

The drug traffickers continued to ply their trade. Large swaths of Afghanistan were left under the control of war lords. Ordinary Afghans, fearful that international forces were going to leave them to the mercy of the Taliban as it became resurgent, were given no incentive to commit to the building of a stable Afghan state. The Karzai regime became increasingly corrupt and dedicated to little more than its own survival.

When Britain deployed to Helmand in the first half of 2006, John Reid made a contribution to the compendium entitled Things Politicians Wish They'd Never Said when he voiced the hope that British troops might return "without firing a shot". Three years and more than 200 casualties later, they are still engaged with the Taliban. The publicly stated objectives of the mission have repeatedly shifted and constant talk of decisive moments has raised public expectations of a successful exit, expectations which have been repeatedly dashed. It was not just the politicians who misunderstood the nature of the task. The top brass of the military lobbied intensively for the deployment to Helmand. Despairing of Iraq, the army thought, as one involved in that decision says, that: "It would be a nice, winnable war."

The hubris of those phrases has now flipped into an equally treacherous despair. I keep reading that Afghanistan is turning into a British "Vietnam". It is also routinely said that Nato must cut its losses and run if it is not to suffer the same fate as the Red Army during the Soviet Union's catastrophic attempt to impose a Marxist dictatorship from Kabul. That defeatism is as glib and dangerous as the earlier delusional triumphalism of the neocons. During the eight-and-a-half years of the Soviet occupation, Russia lost hundreds of aircraft and tanks, in excess of 14,000 troops and more than 50,000 of its forces were wounded. In Vietnam, the Americans suffered more than 50,000 casualties. As I write, the number of American troops killed in Afghanistan is 742 and the number of British is 212. Any loss of life is terrible, but 954 is a long way from 50,000.

It is worth remembering that when the Taliban controlled Afghanistan, only a million children were getting an education, none of them girls. Today, there are more than six million in school, more than two million of them girls. It is an achievement that, thanks to international aid, many more Afghans have access to basic health care. The Taliban have been roundly defeated whenever they have been drawn on to the battlefield which is why they switched to terror tactics. The summer offensive in Helmand, which has won ground but at the cost of a big spike in British casualties, will be a success only if the troops stay to hold and build something for the people. The shortage of soldiers has cramped the ability to secure territory and left their commanders over-reliant on airpower. Misdirected American air strikes have caused mass civilian casualties, like the large numbers killed on the very day Mr Brown made his speech. That is one of the biggest sources of Afghan alienation from the allies.

With a mounting body count, open dissent from some army commanders and no end in sight, it is scarcely surprising that there has been a severe erosion in support for the commitment. It is more remarkable, given the growing unpopularity of the war, that none of the main opposition parties is yet advocating withdrawal. The Conservatives opportunistically seize on every setback, but they are not crying "troops out". In so much as the Tories have a policy, it is to advocate sending more troops in, though they are stumped when asked where they would come from.

The Lib Dems are flirting with a withdrawalist position without actually advocating it. Nick Clegg tells us: "There's a tipping point where we have to ask ourselves whether we can do this job properly, and if we can't do it properly, we shouldn't do it at all." And what is this geostrategist's answer to his own important question? "I don't think we are there yet." That's jolly enlightening from Captain Clegg.

The contribution from Angus Robertson, the leader of the Scottish Nationalists at Westminster, is to call for "a major rethink that looks at all the options". While Major Rethink is doing his pondering, real soldiers are fighting and dying. Eric Joyce argues that "leaving the field to the United States would mean the end of Nato as a meaningful proposition" and he is surely right about that. Yet in his rather confused resignation letter, he urges the prime minister to declare that we are getting out of there pdq.

Britain is fighting the Taliban in Afghanistan for a mixture of reasons: the good, the bad, and the unspoken. An unspoken one is British military pride. Britain's involvement in Iraq had an awful denouement when Tony Blair left such a denuded force of troops in the south that they were forced to retreat to their military base at the airport to leave Basra to the mercy of Iranian-supplied militias and criminal gangs. Authority and order were restored later in Operation Charge of the Knights when the Iraqi army, with the support of the Americans, reclaimed the city. The British army could be broken by another humiliation like that which would make all the previous sacrifice seem in vain.

Another unspoken reason – unspoken, anyway, by Mr Brown – is that a precipitate withdrawal will almost certainly turn an awful situation into a catastrophic one. The Karzai regime is corrupt and compromised. This summer's presidential elections have been flawed and tainted by allegations of fraud. That is bad, but still infinitely preferable to a return to Taliban dictatorship or a civil war. Leaving Afghanistan to descend into absolute chaos would destabilise its nuclear-tipped neighbour, Pakistan, and draw in Iran, India and Russia.

This Mr Brown did not say. What he did say was: "The fundamental reason is to ensure al-Qaida cannot again use this region as a base to plan terrorist attacks across the world." A large proportion of terror plots have originated in the badlands that straddle Afghanistan's southern border with Pakistan. Pakistan is at last making an effort to expel the Taliban from the Swat valley. That will be rendered futile if they and al-Qaida find a safe haven back on the Afghan side of the border. As for an exit strategy, its components ought to include pressure to clean up the government, reaching out to the elements of the insurgency with whom accommodations can sensibly be made and the building up of the Afghan national army, currently less than 100,000 strong. That is a task to which serious attention should have been paid eight years ago. The least convincing suggestion from the prime minister was that this can all be made to happen quite rapidly.

There are still compelling arguments for not abandoning Afghanistan yet again and even Mr Brown managed to muster some of them. But it is going to be protracted, difficult and even a good outcome won't be a perfect one. It is idle to pretend otherwise. The delusion that there are quick fixes and easy exits was what got us into this bloody mess in the first place.