It was a failure because stated US goal was nation-building: that is, creation of a democratic Afghanistan. They failed in that, and it was thus a failure. But fact that pulling out meant that the campaign was a failure does not mean that pullout was a mistake.