I think you're forgetting that the Afghan government directly supported AQ. That government needed to be deposed. Our long term occupation was a mistake, but we did need to get rid of their government.
If you are going to depose a government, realistically you are also committing to some sort of occupation afterwards. There is going to be a power vacuum, and unless you stick around to make sure it is filled correctly, the outcome could be worse.
The problem was thinking otherwise, that it could be done quicker and trying to sell it to the public IMO. Especially in such a lawless and tribalistic region.