Not a defeat at all, even if the invading Taliban would like to portray it that way. A merciless Sunni Pashtun band of leaders in exile negotiate some guarantees and then force their rule over all other ethnic tribes and religions in the land. A sad day for their people and for most of the world to observe.
For 20 years we tried our best to help the people of Afghanistan, and we can leave with a clear conscience on that score. Imagine if we hadn't.
(The timing and manner of closure is untidy and reflects badly, though.) What more could we have done for them? Perhaps the international community failed to win hearts and minds?