John Mueller in Responsible Statecraft:
Postmortems on the war in Afghanistan stress errors of execution during the two decades of occupation. However, the greatest error may have been to invade at all.
Rather than launching a war that proved to be disastrous, an alternative reaction to 9/11 might have been to expand police and intelligence operations and to work with sympathetic allies to pressure the Taliban, which had little or nothing to do with 9/11, to dismember al-Qaida and to turn over its top members.
Several conditions were favorable to such an approach.
First, Taliban rule in Afghanistan was quite unpopular and far from secure. After its takeover in 1996, it had afforded peace and a degree of coherent government to Afghanistan after a horrific civil war. However, by 2001 its popularity had declined due to its chaotic and sometimes brutal rule — and perhaps due to its successful effort to crush the lucrative opium trade in the year previous.
More here.