We did not lose militarily. That is abundantly clear.
I think that depends on what the win condition was. If America's goal in Afghanistan had been a simple and straightforward 'go in, smash things, kill Bin Laden, get out' that could've been achieved by the end of 2001 were it not for these two particular psychos. And it was eventually achieved a decade later anyway, so certainly in that case it wouldn't be inaccurate to say the American people got what they invaded for at long last. But that 20-year, multi-trillion dollar project to 'fundamentally transform' Afghanistan into a sandier and more mountainous Bay-Area-without-the-bay? Obviously didn't go nearly as well. Not that I think any amount of American (or anyone else's) military power could realistically accomplish that goal, even if we had all stayed for another 100 years in Afghanistan.
But for that, let's consider the Clausewitzian maxim that 'war is politics by other means'. The US is obviously not a military dictatorship, its generals and admirals answer to the civilian political leadership, and it's that leadership which set impossible goals which no military could have fulfilled without magic mind-control rays, in the process wasting $2 trillion and thousands of Western lives (and 100,000+ Afghan lives). That was a group project of the entire establishment from Bush to Obama and Biden too, not just Cheney and Rumsfeld, but they played an instrumental part in making it possible by letting Bin Laden and the Taliban get away at the last minute in 2001. Why, what did they hope to gain by prolonging the war? Sure I can guess, but I think this is a fitting place for a quote from ol' Cankles herself - what difference would it make? I can't think of any excuse that would justify deliberately letting America's enemies get away to fight another day (or 7,300 more days, as it were) at a moment where they could've been taken out and the war ended on a swift & victorious note.
If I were American, I'd sooner look into trying Cheney for treason and digging Rumsfeld up for a Cadaver Synod-esque posthumous trial before I looked at punishing Pakistan for undermining Coalition efforts in A-stan. Those two and their cohorts in the American political establishment (of which there are still many, that I don't doubt - hell, Cheney's own daughter is still openly Queen RINO these days) are as much America's enemy as Bin Laden and Mullah Omar were. If not even more-so, since at least AQ and the 'Ban are external enemies rather than internal traitors conspiring to get Americans killed or maimed for their own fun and profit.