The Afghan war, you will remember, was supposed to be the "good war". Unlike the catastrophe of Iraq, from which most former cheerleaders still prefer to avert their eyes, Afghanistan was thought to be different. Senior British military figures might wince in private over their Basra humiliation, but would earnestly insist that they were fighting the good fight in Helmand "at the request of the elected Afghan government". Gordon Brown felt able to tell parliament only six weeks ago that "we are winning the battle in Afghanistan".

But in the wake of a string of reports that the country is fast becoming a failed state and a humanitarian disaster, as armed attacks on western troops and Afghan forces multiply and Nato splits down the middle over sending reinforcements, that looks ever more other-worldly. The US coordinator on Iraq, David Satterfield, even suggested last month that Iraq would turn out to be America's "good war", while Afghanistan was going "bad". After a conflict that has already lasted longer than the second world war, Paddy Ashdown, rejected at the last minute as UN proconsul in Kabul, was clearly closer to the mark than Brown when he declared: "We are losing in Afghanistan."

Tomorrow, the US secretary of state, Condoleezza Rice, arrives in London to discuss Nato's Afghan crisis, triggered by Canada's threat to withdraw its 2,500 troops from Kandahar unless other states bolster the western occupation in the bloodiest areas of the south. But there seems little prospect of anything more than token gestures, after both Germany and France rejected US demands to extend their commitments - despite taunts from the US defence secretary, Robert Gates, about their inability to fight insurgencies. In most Nato states, public opposition to the Afghan war is strong and growing stronger. That includes Britain, where 62% want all 7,800 UK troops withdrawn within a year, a view unshaken by attempts to boost support with military parades and gung-ho Beau Geste-style media reporting from the frontline.

Public cynicism towards Britain's first co-occupation of a Muslim country in the US's "war on terror" can only be deepened by the Afghan president Hamid Karzai's public denunciation last month of the British military role in the south - which had, he said, led to the return of the Taliban. The criticism caused outrage, but Karzai is either a sovereign ruler or he is not. Together with his complaint that he had been strong-armed by the British into removing the governor of Helmand, with disastrous consequences, it clearly cuts the ground from beneath the claim that western troops are simply in Afghanistan to support the government.

Karzai was, after all, installed by the US after the overthrow of the Taliban regime in 2001 and subsequently confirmed in bogus US-orchestrated elections three years later. If even someone regarded as a US-British stooge, whose writ famously barely runs outside Kabul, is reduced to protesting in public that his western protectors are doing more harm than good, that not only makes a mockery of the idea that Afghanistan is an independent state. It also strongly suggests this is a man who recognises that the occupation forces may not be around indefinitely - and he may have to come to more serious terms with the local forces that will.

For all the insistence by Britain's defence secretary, Des Browne, and others that this is a "commitment which could last decades", there is no doubt that armed resistance to foreign occupation is growing and spreading. Nato forces' own figures show that attacks on western and Afghan troops were up by almost a third last year, to more than 9,000 "significant actions". And while Nato claims that 70% of incidents took place in the southern Taliban heartlands, the independent Senlis Council thinktank recently estimated that the Taliban now has a permanent presence in 54% of Afghanistan, arguing that "the question now appears to be not if the Taliban will return to Kabul, but when". Meanwhile, US-led coalition air attacks reached 3,572 last year, 20 times the level two years earlier, as more civilians are killed by Nato forces than by the Taliban and suicide bombings climbed to a record 140. The Kabul press last week predicted a major Taliban offensive in the spring.

The intensity of this armed campaign reflects a significant broadening of the Taliban's base, as it has increasingly become the umbrella for a revived Pashtun nationalism on both sides of the Afghan-Pakistani border, as well as for jihadists and others committed to fighting foreign occupation. The original aims of the US-led invasion were of course the capture of Mullah Omar, the Taliban leader, and Osama bin Laden, along with the destruction of al-Qaida.

None of those aims has been achieved. Instead, the two leaders remain free, while al Qaida has spread from its Afghan base into Pakistan, Iraq and elsewhere, and Afghanistan has become the heroin capital of the world. For the majority of Afghans, occupation has meant the exchange of obscurantist theocrats for brutal and corrupt warlordism, along with rampant torture and insecurity; while even the early limited gains for women and girls in some urban areas, offset by an explosion of rape and other violence against women, are now being reversed. The meaning of "liberation" under foreign occupation can be measured by the death sentence passed last month on a 23-year-old student for blasphemy after he downloaded a report on women's rights from the internet.

The war in Afghanistan, which claimed more than 6,500 lives last year, cannot be won. It has brought neither peace, development nor freedom, and has no prospect of doing so. Instead of eradicating terror networks, it has spread and multiplied them. The US plans to send 3,000 more troops in April to reinforce its existing 25,000-strong contingent, and influential thinktanks in Washington are pressing for an Iraqi-style surge. But only a vastly greater deployment could even temporarily subdue the country, and that is not remotely in prospect. The only real chance for peace in Afghanistan is the withdrawal of foreign forces as part of a wider political settlement, including the Taliban and neighbouring countries like Iran and Pakistan. But having put their credibility on the line, it seems the western powers are going to have to learn the lessons of the colonial era again and again.

s.milne@theguardian.com