The Bad-Ass Librarians of Timbuktu. By Joshua Hammer. Simon & Schuster; 278 pages; $26.

JOSHUA HAMMER’S new book, “The Bad-Ass Librarians of Timbuktu”, traces the story of hundreds of thousands of medieval texts as they are rescued in 2012 from near-destruction by jihadists linked to al-Qaeda in Mali. It is at once a history, caper and thriller, featuring a superherolibrarian, Abdel Kader Haidara, as the saviour of an entire culture’s heritage.

Some of the book’s most compelling passages are lists, sometimes as much as a paragraph in length. The spices, minerals, animals, fabrics and books carried into Timbuktu in the Middle Ages give a heady taste of what the city once was. The printing process swirls to life in red, gold and black inks, on paper from Fez or distant Venice. Three craftsmen were needed to create a manuscript: one for the words, another for the proofreading and a third to dash in the delicate intonation markings. Yet the tension, whether to share the texts or hide them, is ever-present. These millions of pages become the endangered species of the story, threatened by wave after wave of invaders.

Mr Hammer’s book is not strictly about the manuscripts, for their escape does not really start until halfway through the book. It is mostly a history of jihad in Mali, which for centuries lay on the trade route across the Sahara. One day, a short sandy drive from his hero librarian’s home, a “butterscotch-and-peach painted concrete mosque” appeared to Mr Hammer: an outpost of the puritan, Saudi-funded Wahhabi ideologues taking root across the Sahel. He first sees the new mosque on a visit to Timbuktu before the war, when he also spots American special forces drinking beer in the heat. Trouble was brewing.

The story picks up speed as it begins to chart the opening salvos of Mali’s own Arab spring. France and America watch a weak region, infested with criminals, moulder. Military officials want to strike extremist groups as they form, they tell the author, whereas diplomats prefer development. Hostages are taken from Mali and neighbours, and traded for huge ransoms. The Tuaregs who supported the Libyan leader, Muammar Qaddafi, come home armed and ready for revolution. Just as the fight is brewing, a world-renowned music festival in Timbuktu welcomes Bono to the stage. Four days later, after the tourists leave, the shooting begins.

Life becomes awful in Timbuktu, with brutal sharia punishments meted out by young soldiers. Many Malians refuse to be cowed. Here the caper begins at last. Mr Haidara, the dogged manuscript collector who has spent a lifetime gathering north Africa’s most important works into central libraries, faces a difficult, at times insane, task: how to smuggle nearly half a million ancient texts from under the jihadi occupiers’ noses down a 1,000km route to Bamako. He develops an ulcer as a result of the stress.

The reader last encounters the troves of manuscripts as they arrive at safe houses in Bamako; “not one had been lost”, according to Mr Haidara. Here the author leaves them, as fragile, tantalising and inaccessible as they were in the desert. What of their future? For the ancient books themselves, this chapter is one among many.