I was contemplating what went wrong in Afghanistan when we essentially did the same thing in Japan and Germany which turned out pretty well for us all things considered. It's a vicious cycle of blame and bureaucracy. You want to rail at Biden for leaving, but apparently we spent the entire 20 year period guaranteeing we'd have to. The post has an article that goes into detail about how we fucked at this up.
What went wrong is that our economy was so badly in the toilet during the Great Depression that World War 2 actually gave us a substantial boost from all the jobs that the war created and thus allowed the U.S. to finally dig ourselves out of that hole. We we so bad off that war ended up benefiting instead of costing us. If it wasn't for World War 2 the Great Depression would likely have lasted for many years longer, decades even despite the measures we were taking at the time to try to get out of it.
Since then? Ever war we've been in we've either lost, got nothing out of, or both. The military in general hasn't done anything except waste money and lives for nothing in over 70 years. 9/11 was the worst example of this, we started 2 completely pointless wars that we not only didn't benefit from but cost us literally trillions of dollars and countless lives even just on our side not to mention theirs. We weren't far off from causing a second Great Depression to ourselves. What's worst of all, we proved beyond a shadow of a doubt that terrorism works. What we should have done was, for a microscopic fraction of what we spent on these wars, simply beefed up our security, grieved a bit, and got on with our lives. Maybe have a special forces unit sneak into Afganistan and snipe Bin Laden and his cronies from a mile away if we really cared about getting revenge, and once again for a insignificant fraction of the time, money, and lives that the actual wars cost us.
What we did as a result of 9/11 is exactly what terrorism is designed to do, scare the target stupid so they do more damage to themselves than any number of terrorist attacks could have done. A hundred 9/11s couldn't have done as much damage at least financially that we did trying to "fight" terrorism, and thanks to what we did we probably will be facing a hundred 9/11s in the future from all the terrorist groups we'll have birthed from going out of our way to tank the reputation of the U.S. on top of proving the validity of the tactic known as terrorism.
It's about time someone decided to actually pull out and leave these guys to their own devices. We were going to have to do that anyway and they'd reverse probably in a tiny fraction of the time everything we might have actually accomplished in those countries. We didn't even conquer either country and add them to U.S. territory much less get anything else we could've gotten out of it so in the end it was completely pointless.
In short, what went wrong was that we didn't consider the consequences of our actions and definitely if what we were doing was actually worthwhile.