For centuries, poets, scholars and theologians have flocked to Chinguetti, a trans-Saharan trading post home to more than a dozen libraries containing thousands of manuscripts.

But it now stands on the brink of oblivion. Shifting sands have long covered the ancient city’s 8th-century core and are encroaching on neighborhoods at its current edge. Residents say the desert is their destiny.