The decision to invade Iraq is probably the main reason Afghanistan became such a mess. America cut and ran from it's responsibility in Afghanistan in 2003 not last week.
I think this was a project doomed to fail no matter what. Just like Vietnam you'd have to essentially kill all of the insurgents in order to stop them from fighting.
Afghanistan is a country filled with a lot of violent Muslim extremists and there's not much to be done about that save killing them all, which is virtually impossible.