The Afghan war, the longest in US history, is "scheduled to end" a year early, according to the Pentagon. Wars these days run to electoral timetables. The endgame is couched not as victory, let alone defeat, but as "expedited withdrawal".

It is obvious that Taliban commanders are reading Sun Tzu, and "building the enemy a golden bridge across which to retreat". They are talking to go-betweens, opening offices in Doha and giving soothing interviews. This week's leaked American intelligence report, The State of the Taliban, shows that the Afghan people, too, are coming to terms with the return of their former rulers, and might even welcome some stability and order after 10 years of Nato-induced chaos.

The US president, Barack Obama, has always hated this war of neocon fantasy, and is now calibrating his departure. Militarily, the path to defeat has been straightforward. While it is easy to bomb a capital and deploy armies to topple a regime, occupying foreign countries for any length of time is usually disastrous. Soldiers become brutalised, allies desert, operations become costly and counterproductive.

Nato strategists did not need Napoleon or Hitler for a warning, merely Soviet experience in Afghanistan in the 1980s. Even after Mikhail Gorbachev saw the writing on the wall and decided to withdraw in 1985, it took him four years to do so. As also indicated in this week's report, the Pakistanis, supposedly allies of the west, have long sided with the Taliban. Even Kabul's ruler and western puppet, Hamid Karzai, has said he would support Pakistan in any putative war with the US. It does not matter what America or Britain does. The logic of a prolonged occupation of a Muslim country is remorseless.

More alarming about the Afghan war has been its psychology. It has generated some two dozen books on my shelf, and every one of them warns, cautions, criticises, condemns. The Pashtun Taliban should not be underestimated. Defeating them by main force flew in the face of all experience. Pakistani intelligence would offer them sanctuary and support. Nato should not drive al-Qaida, a tiny Arabist cell in 2001, into alliance with the Taliban. The idea that force of western arms could turn a corrupt Muslim statelet into a sanitised, pro-western democracy was arrogant and unreal.

Every warning was disregarded in a classic of "cognitive dissonance". The Afghan war has been sustained by years of mendacity and deceit from western governments. Elected representatives, the media and public opinion were induced to buy the line that success was "just around the corner". Embedded journalists would report that the army was "winning hearts and minds" and the Taliban were on the run. Sooner or later Nato would "retrain" the Afghan army, despite constant reports of the hatred and unreliability this army felt towards the occupation. Just last week, the British government bizarrely pledged to build "an Afghan Sandhurst", presumably as a palace for some future Taliban warlord.

All military and diplomatic experience, all the history and the scholarship in the world, did not stop this crude punitive venture being backed by conservatives and liberals alike in both the US and Britain. It was declared a good war. The drumbeats of battle stifled criticism. Any general got a cheer who could boast that the war would be over in weeks, and without a shot fired. Critics were met with the timeless, drear refrain, that their talk was defeatist, cowardly and lacked patriotism. Like Rhett Butler in Gone with the Wind, they were drowned by the lust for glory.

Nor were the lobbies idle. Bruised from its Iraq debacle, the British army wanted somewhere to walk tall. Helmand, with its echoes of Beau Geste and Lawrence of Arabia, was ideal. Behind the army lurked the call of money, an ever-burgeoning regiment of arms suppliers, security firms, contractors, NGOs and aid agencies, all fat on the war's staggering $500bn cost. Add to them Kabul's kleptocrats, politicians and aid recipients, and the war took on a self-sustaining quality. Even today few participants have an interest in its ending. Hundreds, then thousands, die, and no one can honestly say why.

Withdrawal will not be as easy as from Iraq, messy and unresolved as that remains. The new Taliban may be media-friendly and, for the present, amenable to calls for moderation. They are said to be more sophisticated than those who seized Kabul amid appalling bloodshed in 1996. But it is hard to believe their leaders will have cause to compromise in a year's time, hailed as heroes of Islam for having humbled the might of Nato. Their Pakistani backers will be equally exhilarated. Whatever might have been achieved against al-Qaida with minimal force in 2001 – on which I recommend Lucy Morgan Edwards' book The Afghan Solution – is past history. Resumed chaos beckons.

Unlike most European countries, sucked into the Afghan vortex by Nato blackmail, Britain and the US were willing warriors, with belligerence in their cultural genes. Discussing "what must be done" to order the rest of the world is second nature to their political class. Successive British governments bought into the lies and scaremongering of George Bush's war on terror. Gordon Brown and David Cameron alike claimed that the killing fields of Helmand were integral to safety on the streets of London, and indeed to the security of the British state. People believed them. War induced a cockeyed credulity.

The Afghan war has not made the west one jot safer, almost certainly the reverse. Islamist terrorism and its obverse, panicky security, is polluting this year's Olympic Games in London. Yet the war clearly responded to a yearning in many Britons to see the world as still their ancestral responsibility. To them a war that turns out right, such as in Libya, "proves" Britain's manifest destiny.

Which is why this is not the endgame. Britain is even now rattling sabres and dicing with disaster alongside the US against Iran. Such a war would be as catastrophic as could be imagined, and against a country that poses no conceivable threat to western security. The sole reason for going to war against Iran is to go to war against Iran. That is how we went to war against Afghanistan and Iraq. Clearly, nothing has been learned.