In September 2001, terrorist attacks in New York and Washington had just wounded the United States. Yet the West looked invincible, not just morally but militarily. Indeed, by the time I arrived in Afghanistan later that month, it seemed clear that the Taliban regime — which had harbored the attacks’ al-Qaida masterminds — was doomed.

Twenty years later, the picture has changed. As the Taliban advances, the U.S. and its allies face the greatest humiliation since the fall of Saigon. The full bill is yet to come due. But it is already clear that while our adversaries, chiefly China, have bolstered their resources and prestige, we have squandered ours.

I cannot judge how far the Afghan intervention was wholly misconceived and how far it was merely botched. Either way, we have almost nothing to show for it. Even Faizabad, the anti-Taliban stronghold where I and other journalists were based in the fall of 2001, is now besieged. I wonder what will happen to the university, the TV station, and the girls’ school.

The trust that underpins U.S. leadership has been strained. Allies — notably in eastern and central Europe — were asked, indeed expected, to contribute to the Afghan and Iraqi wars as a sign of their commitment to NATO. True, we learned some lessons about low-intensity warfare. But they are not particularly useful in dealing with Russia and China. The rendition of terrorist suspects drew allies such as Poland and Lithuania into a hideous underworld of secret prisons and torture, obscured with a carapace of deceit.

Our politicians insisted (again and again) that this was a war of necessity, not of choice. Our generals told us (again and again) that it was winnable. In retrospect, our decision-makers seriously overestimated the danger from Iraq and Afghanistan. They grossly underestimated the threat we faced from Russia and China. Some of them still do.

We neglected the vital task of building European, and Pacific, security. Budgets for territorial defense shriveled while colossal efforts went on fighting unwinnable wars in faraway countries. We became dependent on friendly ties with Vladimir Putin’s Russia (whose help was vital in maintaining the northern supply route to Afghanistan). For the same reason, we cozied up to dictatorships such as Uzbekistan. We paid too little attention to the heroin that flowed in the other direction.

Rebuilding trust is the priority now. It will require honesty and humility. We need searching, bipartisan inquiries in London, Washington DC, and other capitals into what went wrong and how. With truth should come apologies. There is plenty of blame to go around.

The human aftermath needs attention too. The Afghans who helped us and believed in our values now face death if they cannot flee. They must wonder why they trusted us. Many Vietnamese will find this familiar. The callous treatment of the boat people fleeing the communist regime in the late 1970s was a terrible example of how a retreating empire shirks its responsibilities.

We should get it right this time, with generous visa and resettlement arrangements not only for translators and others directly linked to the Western military presence (and their families), but for those who face persecution on grounds of sex, ethnicity, education, or other characteristics that will incur the wrath of the zealots and bigots now coming to power.

This will be costly. But financial constraints have not stopped us making hugely expensive mistakes in the past 20 years. They should not prevent us following the right course now. If Western countries want to rebuild the strategic credibility they lost in Afghanistan, they can start by shouldering their responsibilities to its people.