At the end of 20 years, US indirectly had to negotiate with them.
So the other way of looking at it is, a bunch of un-educated, poorly trained, poorly equipped mountain people, who themselves are divided into many warring factions, stood their ground against the mightiest nation on earth, for 20 year, and in the end US negotiated with them for transfer of power.
Now, I see this as sheer political and administrative failure. Militarily, sure, the US has an upper hand and can pile up bodies like no other, But it failed to win the "war on terror" in Afghanistan. It could not change the govt., it could not bring stability and democracy to the region, it could not transform the society, and it could not even change the idea of itself in the minds of the Afghan people.
US is too powerful, militarily, to formulate effective strategies that further its goals. It is good in doing that economically, through sanctions, etc. But as a military force, it is too powerful for its own good.
Even Churchill said of them: "Every man is a warrior, a politician and a theologian."
The Afghans have no proper education system, no institutions other than local commanders directing their bunch of troops and have virtually no good infrastructure. They literally live among mountains and have no good networks for transportation.
I am giving the Afghans a lot of credit, because what I said about them is true. They won in spite of that.
I suppose one could say that the US hasn't lost yet, but it's pretty tough to say that the US has won.
Honestly, at this point it feels like any discussion of the US staying in Afghanistan seems like it should devolve into a discussion of the halting problem. (/s, but only slightly)
The US just signed a peace deal with the Taliban agreeing to and withdraw all their troops and release aligned 5000 prisoners, the Taliban are also allowed back in government. Technically they could be in power at the next election.
What actual goal was fulfilled here after two decades of war?
Al-Qeada and other groups just shifted to other unrested regions and even caused unrest. At a global scale the war only caused other countries harm.