US did not occupy the country- they occupied the big cities and a built a huge airbase. Countryside was in Taliban hands for the most part.
US never closed the border with Pakistani - and the talibans retreated in Paki when under attack and then went back in Afghanistan when things calmed down.
In Afghanistan US won as much as it won in Vietnam.
Then their failures to bulld a stable government brought the Taliban back.