The US spent years fighting north Vietnamese forces only to sign a peace treaty, leave south Vietnam and then 2 years later have North Vietnam take over South Vietnam and unify the country.
You don't consider completely failing your objectives failure?
In both cases, Washington chose to stop sustaining a local government that could not survive on its own.
Saigon fell on April 30, 1975, which was a little over two years after the last US combat troops left Vietnam on March 29, 1973. US did not lose Afghanistan on the battlefield. US military overthrew the Taliban government, dismantled al-Qaeda’s sanctuary, killed Osama bin Laden, and prevented another major foreign-directed terrorist attack from Afghan soil for nearly twenty years. American forces were not defeated or driven out; they left because elected political leaders decided the mission was no longer worth continuing.
In both cases, the threats were eliminated. Hanoi is now friendly to the US. Iraq is friendly to the US. Syria is friendly to the US.
The USA apparently sees these little wars as investments or something. It's getting too expensive: cut losses and pull out the troops.
A real "USA loses" scenario involves the White House flying a foreign flag. A real defeat of the USA would probably shock americans to the core. Fully expect them to lash out with nuclear weapons if such a thing ever happens.
Is that and act of victory or defeat ?
Defeat is the US military getting routed and decimated. Defeat is US aircraft carriers sinking to the bottom of the ocean. Defeat is Washington getting nuked.
What actually happens is the opposite. Americans show up and inflict staggering casualties while suffering a relatively small anount. Then they suddenly leave for some idiotic reason like the president wanting reelection.
America's enemies don't need to actually win, they just need to resist as long as possible and drive up the costs of the war via asymmetric warfare.
US achieved major objectives, failed at building self-sustaining governments, and eventually withdrew.
It was a civil war that the US got involved in, and they supported the side that lost.
Who governs those countries matters, but America cannot spend unlimited blood and treasure ensuring that every country is governed by people we approve of.
The threats were eliminated. Mission accomplished.
Ask Pakistan if the threat of Afghanistan-based terrorism has been eliminated.