The Niger River narrows as it nears Lake Debo, an inland sea formed by the seasonal flooding of central Mali’s Niger Delta. With sandy banks covered in reeds and tall grass, this stretch of the river makes an ideal sanctuary for bandits, and on January 20, 2013, the area was particularly violent and lawless. French military helicopters swept through the skies, bound for Timbuktu, to drive out militants who had occupied the city. Skirmishes between French ground troops and jihadists were breaking out just a few dozen miles away.

Into this chaos came a fleet of 20 motorized skiffs, sticking close to the center of the waterway. At the entrance to Lake Debo, dozens of turbaned men brandishing Kalashnikovs appeared on both banks, and ordered the boats ashore. The men eyed the cargo—300 metal footlockers, 15 to a boat—with curiosity. Inside they found stacks of crumbling manuscripts, some bound in leather. Dense Arabic texts and brightly colored geometric patterns covered the brittle pages. It was clear that the books were old, and from the worried looks of the young men guarding them, they seemed valuable. The gunmen told the escorts that they would have to pay a ransom if they ever wanted to see the volumes again.

The young men tried to placate the hijackers. They peeled off their cheap Casio watches and proffered them, along with silver bracelets, rings and necklaces. “All the kids in the north wear jewelry, that’s part of their look,” says Stephanie Diakité, an American lawyer and manuscript restorer in Bamako, Mali’s capital, who helped organize the boatlift. “They gave them all of that, like that was going to suffice, but it didn’t do the job.”

At last the couriers called Abdel Kader Haidara, a Timbuktu native who had amassed Mali’s most valuable private collection of manuscripts, and also oversaw an association of Timbuktu residents holding their own libraries of manuscripts. “Abdel Kader got on the phone, and he said to the hijackers, ‘Trust me on this, we will get you your money,’” says Diakité. After some consideration, the gunmen allowed the boats and their footlockers, containing 75,000 manuscripts, to continue. “And we paid them four days later,” says Diakité. “We knew we had more boats coming.”

Contemporary scholars consider Timbuktu’s Arabic-language manuscripts to be among the glories of the medieval Islamic world. Produced for the most part between the 13th and 17th centuries, when Timbuktu was a vibrant commercial and academic crossroads at the edge of the Sahara, the volumes include Korans, books of poetry, history and scholarly treatises. Fields of inquiry ranged from the religious traditions of Sufi saints to the development of mathematics and surveys of breakthroughs in Graeco-Roman and Islamic astronomy. Merchants traded the literary treasures in Timbuktu’s markets alongside slaves, gold and salt, and local families passed them down from one generation to the next. The works reveal Timbuktu to have been a center of scientific inquiry and religious tolerance, an intellectual hub that drew scholars from across the Islamic world.

At a time when Europe was just emerging from the Middle Ages, Timbuktu’s historians were chronicling the rise and fall of Saharan and Sudanese monarchs. Physicians documented therapeutic properties of desert plants, and ethicists debated the morality of polygamy and smoking tobacco. “These manuscripts show a multiethnic, multilayered community in which science and religion coexisted,” says Deborah Stolk of the Prince Claus Fund in the Netherlands, which has supported manuscript preservation in Timbuktu. The family collections, she adds, “are filled with works laden with gold and beautiful drawings. We’re still discovering what is there.”

The crisis in Timbuktu began in the spring of 2012, when rebels from the Tuareg tribe—who have long aspired to create an independent state in northern Mali—allied with Islamic militants. The joint force, armed with heavy weapons looted from the armories of the late Libyan dictator Muammar el-Qaddafi, overran the northern parts of the country and seized control of Timbuktu and other towns. The jihadists soon shoved aside the secular Tuaregs, declared sharia law and began attacking anything they perceived as haram—forbidden—according to their strict definitions of Islam. They banned singing and dancing, and forbade the celebration of Sufi Islamic festivals. They demolished 16 mausoleums of Timbuktu’s beloved Sufi saints and scholars, claiming that veneration of such figures was a sacrilege. Eventually the militants set their sights on the city’s ultimate symbols of open-mindedness and reasoned discourse: its manuscripts.

A network of activists was determined to thwart them. For five months, smugglers mounted a huge and secret operation whose full details are only now coming to light. The objective: to carry 350,000 manuscripts to safety in the government-held south. The treasures moved by road and by river, by day and by night, past checkpoints manned by armed Islamic police. Haidara and Diakité raised $1 million to finance the rescue, then arranged for safe storage once the manuscripts arrived in Bamako.

The risks were great. Rescuers faced the possibility of arrest, imprisonment or worse at the hands of the thugs who had taken over the north. Militants from Al Qaeda in the Islamic Maghreb were capable of acts of enormous cruelty. They flogged women who went about uncovered, chopped the hands off thieves, carried out public executions and held opponents in dank, overcrowded jails for days without food or water. One resident watched Islamic police stomp on the belly of a pregnant woman who had dared to step outside to fetch water without putting on her veil; she miscarried the baby on the spot, he says. “We knew they were brutal, and we were terrified of what would happen to us if we were caught,” said one courier who transported manuscripts to Bamako. Months later, many of those involved in the manuscript evacuation are still afraid to divulge their roles. They are worried that the jihadists could reconstitute themselves in Mali’s north and take revenge on those who humiliated them.

***

Abdel Kader Haidara, 49, could hardly have imagined that he would be thrust into the center of a dangerous scheme to outwit Al Qaeda. A large man with a boisterous laugh and gregarious manner, he was born in Bamba, not far from Timbuktu. His father, Mamma Haidara, was a scholar, archaeologist and adventurer who searched villages and desert oases for manuscripts on behalf of the Ahmed Baba Center, a government library that had opened in Timbuktu in 1973 with funding from Kuwait and Saudi Arabia. When he died in 1981, Abdel Kader took over his work. “I traveled by pirogue, by camel, negotiating with village chiefs,” Haidara told me in March 2006 in Timbuktu, where I had flown to write a Smithsonian article about the city’s rediscovery of its literary treasures after centuries of neglect. Haidara had grown up surrounded by manuscripts and instinctively could assess their value. Through persistence and shrewd bargaining, he acquired thousands of them for the Ahmed Baba Center.

Then he decided he wanted a library of his own. “I tried to get funding, but it wasn’t easy,” he said. His breakthrough came in 1997, when Henry Louis Gates, the Harvard University professor, visited Haidara in Timbuktu while making a television documentary series about Africa and saw his family’s manuscript collection. “Gates was moved, he cried, he said, ‘I’m going to try and aid you.’” Gates secured initial funding from the Mellon Foundation, and the Bibliothèque Mamma Haidara was born.

In January 2009, when I again passed through Timbuktu, Haidara had put the finishing touches on a handsome building filled with vacuum-sealed glass cases in which some of his prizes were on display. They included an 1853 letter from Sheik al-Bakkay al-Kounti, a spiritual leader in Timbuktu, beseeching the reigning sultan to spare the life of the German explorer Heinrich Barth. The sultan had barred all non-Muslims from the city under penalty of death, but al-Kounti’s eloquent plea persuaded him to release Barth unharmed. “The manuscripts show that Islam is a religion of tolerance,” Haidara told me back then. Scholars from around the world were visiting Timbuktu to study his collection, which numbered 40,000 volumes, as well as those of dozens of libraries opened in the last few years.

***

On April 1, 2012, when Tuareg rebels and jihadists rolled into Timbuktu, Haidara was apprehensive, but he took a wait-and-see approach. “We had no idea what their program was,” Haidara told me when I encountered him again in August 2013, while he was living in self-imposed exile in Bamako. “We thought they might leave after a few days.”

At the time Haidara also had no idea if the militants knew how many manuscripts were in Timbuktu or how valuable they were. But quietly, determined not to attract attention, he laid contingency plans. With funds that Haidara’s library association already had on hand from foreign donors, he began purchasing footlockers in the markets of Timbuktu and Mopti, and delivered them, two or three at a time, to the city’s 40 libraries. During the day, behind closed doors, Haidara and his assistants packed the manuscripts into the chests. Then, in the dead of night, when the militants slept, mule carts transported the chests to safe houses scattered around the city. Over three months, they bought, distributed and packed nearly 2,500 footlockers.

In May 2012, Haidara moved with his family to Bamako; the Internet had collapsed in Timbuktu, as had most phone service, and communication with the outside world was becoming difficult. Haidara “held out hope,” he says, that the manuscripts could remain in the safe houses. But that hope was dashed when the jihadists seized all power in Timbuktu and began turning the desert outpost into an Islamic caliphate.

***

One August morning, in the middle of Mali’s rainy season, I set out in a four-wheel-drive vehicle for Timbuktu to see what the jihadists had wrought. Three Timbuktu natives joined me for the two-day, 450-mile journey: Baba Touré, my driver; Azima Ag Mohammed Ali, my Tuareg guide; and Sane Chirfi, Timbuktu’s tourism director, who had requested a lift home after a year in Bamako.

We spent the first night in Mopti, a riverside town that had been a popular backpackers’ destination before radicals began kidnapping and killing Western tourists. At dawn the next morning we followed a cratered dirt road that devolved into a track through the sand. A light dusting of green covered the normally desolate landscape. After ten grueling hours, the track petered out at the Niger River; we caught a rusting ferry to the other side and followed a paved road for the last eight miles to our destination.

Chirfi stared pensively out the car window as we drove down near-deserted streets lined by mud-brick houses. At the Sidi Mahmoud Cemetery, a bleak expanse of sand dunes on the outskirts of Timbuktu, we stopped before a ten-foot-high pile of bricks and stones. On June 30, 2012, Islamic militants had destroyed this Sufi saint’s tomb with hammers and pickaxes, along with six others, a desecration that horrified the population. Al Qaeda’s leaders “told us that we had deviated from Islam, that we are practicing a religion full of innovations, and not based on the original texts,” said Chirfi. “It alerted us that the manuscripts would also be in danger.”

***

In Bamako, delegates from Unesco, the United Nations’ Paris-based cultural protection agency, were also worried about the manuscripts. The team wanted to organize a public campaign to draw attention to the extremist threat, and pressed Haidara to participate. Haidara believed that it was a foolish idea. Up to this point, the militants had barely mentioned the manuscripts, except for a brief televised address in which they promised to respect them. Haidara was afraid that if Unesco focused on their value, the jihadists would try to leverage them for political gain. “We wanted Al Qaeda to forget about the manuscripts,” he told me. The U.N. officials agreed to back off, but it wasn’t clear how long they would do so.

Other events created a sense of urgency: Lawlessness was on the rise in Timbuktu, and armed men were breaking into houses, grabbing everything they could get their hands on. “We suspected that they would move from house to house, searching for manuscripts to destroy,” said Abdoulhamid Kounta, who owns a private library in Timbuktu with 5,000 volumes. “They never did that, but we were afraid.” And in August 2012, ultraconservative Islamists in Libya burned down a library containing hundreds of historic books and manuscripts. “I was shocked,” Haidara said. “I realized that we could be next.”

The tipping point came when the jihadists—signaling that they were feeling more secure militarily—removed most of the roadblocks in their territory. Stephanie Diakité, the American manuscript-restoration expert who found a life’s calling in Mali when she first saw the manuscripts during a trip to Timbuktu more than 20 years ago, told Haidara that they had no time to lose. “We’ve got to get them out now,” she said.

***

Early on a September morning, two of Haidara’s couriers loaded a 4x4 with three footlockers filled with hundreds of manuscripts and set out for the long drive through jihadist territory. They hit the first checkpoint just outside Timbuktu, exhaling with relief as the armed guards waved them through. One more checkpoint, in Douentza, lay between them and the government border. Again, they passed without incident. Two days later, they arrived safely in Bamako.

Soon afterward, however, Al Qaeda guards stopped a 4x4 heading south, discovered a trove of manuscripts in the back and ordered the vehicle at gunpoint to go back to Timbuktu. Islamic police turned over the cache to Abdelhamid Abu Zeid, the Al Qaeda commander, a soft-spoken murderer who sensed that something valuable had dropped into his lap. Timbuktu’s Crisis Committee—a group of elders who represented the town’s population—pleaded with him to release them. “We guarantee that the manuscripts are simply being taken out of Timbuktu for repairs,” a committee member told the terrorist chief. “And then they will be brought back.” To the rescuers’ relief, Abu Zeid allowed the manuscripts to leave after 48 hours.

The close call shook Haidara, but it didn’t deter him. Every morning for the next three months, his couriers—often the teenage sons and nephews of Timbuktu library owners—made the same perilous journey. Over 90 days, they evacuated an average of 3,000 manuscripts a day. “We were scared for our couriers, they were just kids,” says Diakité. “We could not sleep a lot of the time the evacuations were going on.”

The trip through the jihadist zone was harrowing, but government territory could be just as stressful. The Malian Army, on the lookout for weapons being smuggled into the south, had set up 15 checkpoints between the edge of the jihadist zone and Bamako. “They would open up everything,” Haidara said. “The manuscripts are fragile, and if you rifle through the chests you can easily destroy them. We had to spend a lot of money to calm the situation.”

To that end, and to pay Haidara’s legions of couriers, the Prince Claus Fund, a longtime patron, contributed $142,000. An Indiegogo crowd-sourcing campaign raised another $60,000.

Then, without warning, the situation on the ground changed, and Haidara had to come up with a new plan.

***

One overcast morning my guide, Azima, and I drove eight miles south of Timbuktu to a decrepit port on the Niger River and boarded a pinasse, a 40-foot wooden cargo boat with an outboard motor. We traveled slowly downriver, passing desolate sand banks broken by solitary thorn trees. We beached at Toya, a fishing village of rectangular mud huts lined up for a quarter-mile along the sand. Women washed clothing in the shallows, and the rising sun cast a blinding silver glint across the wide, olive-green waterway.

In early January, the jihadists abruptly stopped all vehicle movement in and out of Timbuktu. “It was completely closed off, and we didn’t know why,” Haidara said. As he would later learn, the militants were secretly preparing a massive assault on government forces in the south and wanted to keep the roads clear of traffic. Haidara was obliged to seek out an alternate route: the river.

Haidara’s couriers began bringing footlockers filled with manuscripts by mule cart to Toya and ten other villages along the Niger. Mohamman Sidi Maiga, a village elder, led us up from the beach through warrens of mud-walled homes and showed us a windowless shed beside his house. “I hid plenty of manuscripts in there,” he told me. “We knew that they would be in danger from the jihadists, so everybody in the village offered to help.”

Despite the risks to their lives, Timbuktu’s boatmen were eager to transport the valuable cargo, both because they had been largely unemployed since the crisis began, and because they believed that the manuscripts “were their heritage, ” says Diakité. Haidara laid out the rules: each pinasse would have two couriers and two captains, so they could keep moving on the river 24 hours a day. No vessel could carry more than 15 footlockers, to minimize losses should any particular boat be seized or sunk. Just after the new year, 2013, the first vessels set off for Djenné, an ancient market town two days down the Niger, just beyond jihadist territory. Taxis met the boats in Djenné’s port and continued the journey to Bamako.

***

On January 9, 2013, a thousand Islamic militants in pickup trucks and 4x4s attacked Konna, in central Mali, the front line of the Malian Army. The government troops fled in panic, tearing off their military uniforms to blend in with the civilian population. Al Qaeda now threatened to seize the region’s main airport and possibly head toward the capital. Responding to the Malian government’s desperate plea for help, French President François Hollande dispatched 4,500 elite troops to Mali from bases in Burkina Faso on January 11. Helicopters blasted the jihadists in Konna, inflicting heavy casualties. Then, with the militants in retreat, the French began advancing toward Timbuktu. The endgame had begun.

The arrival of the French was a godsend for the population, but a potential disaster for the manuscripts. The jihadist leaders summoned Timbuktu’s Crisis Committee to City Hall. The city was preparing for the Maouloud festival, a weeklong celebration of the Prophet Muhammad’s birthday that includes the public reading of some of the city’s most revered manuscripts. “You need to bring us those manuscripts, and we are going to burn them,” the militant commanders said, “so that we can show the French that if they dare to enter the city, we will destroy them all.”

Haidara and Diakité were terrified. Nearly 800 footlockers remained hidden in safe houses in Timbuktu, and the money had all but run out. Diakité manned the phones in Bamako, raising several hundred thousand dollars from Dutch foundations in days—enough to finish the boatlift. “This was the most unpredictable, dangerous time,” says Haidara. It was during this period that the 20-boat flotilla was hijacked by gunmen near Lake Debo. And around the same time, a French helicopter circled a second convoy on the Niger. The pilots shone their spotlights on the skiffs and demanded that the couriers open the chests or be sunk on suspicion of smuggling weapons. The pilots flew off when they saw that the chests were filled with only paper.

***

Timbuktu was descending into chaos. French fighters bombed Al Qaeda’s barracks and Abu Zeid’s residence—a villa that once belonged to Qaddafi. At the Ahmed Baba Institute of Higher Learning and Islamic Research, an $8 million library built by the South African government and used by militants as a dormitory since the previous April, the jihadists prepared for one final act of desecration. On Friday, January 25, they entered the restoration and digitization rooms, where experts had once scanned and repaired crumbling, thousand-year-old pages. With French ground troops just a few miles away, they put 4,202 manuscripts in a pile in the courtyard, doused them with gasoline and set them on fire.

Six months later, when I visited the center—a modern, Moorish-style complex—it still bore the scars of the jihadists’ malicious act. Curator Bouya Haidara (no relation to Abdel Kader Haidara), a slight man wearing a white skullcap and purple boubou, a traditional flowing gown, showed me a concrete column charred black from the inferno. “A local man saw all the smoke, and he rushed in, and at that very moment the jihadists fled,” he said, still agitated six months after the calamity. They were able to retrieve a few scorched pages from the inferno, but the rest had burned to ashes. “We lost manuscripts from the 12th to 16th centuries—about math, physics, all the sciences,” he said. The losses could have been far worse. During their ten months living at the Ahmed Baba Institute, the jihadists had never once ventured downstairs to the basement to inspect a dry, dark storage room behind a locked door. Inside were stacks containing 10,603 restored manuscripts, the finest in the Ahmed Baba collection. All of them survived.

I returned to Bamako from Timbuktu the next morning and met Abdel Kader Haidara at a French-style café in a residential neighborhood along the Niger. I had been eager to find out what had happened to the manuscripts when they arrived in Bamako, and Haidara, after some gentle prodding, had agreed to show me. We rode in his 4x4 through the rutted dirt streets to a large house behind a high wall. Haidara, resplendently dressed in a pale blue boubou and maroon skullcap, unlocked the door to a storage room and beckoned me inside. “Voilà,” he said. He gestured proudly to some 300 footlockers—large metal trunks and smaller ones made of silver-filigreed wood—stacked ten feet high inside the musty chamber. “There are 75,000 manuscripts in this room,” he told me, including works from the Bibliothèque Mamma Haidara and 35 other collections. Another 275,000 were scattered in houses across Bamako, held by a large network of friends and family who had resettled here after the jihadists seized Timbuktu and had volunteered to take in manuscripts. “They still don’t want their identities revealed,” he told me. “They aren’t convinced the war is over.”

Neither were many others. Though French and African peacekeepers were in control of Timbuktu, Al Qaeda militants were still active in more remote areas of northern Mali and sporadic kidnappings and killings continued to plague the region. Even so, Haidara was cautiously optimistic, and making plans to transport the works back to Timbuktu as quickly as possible. The humidity in Bamako—especially during the rainy season, when daily downpours turn the dirt streets to mud and a permanent dampness hangs in the air—was already bloating the ancient pages, he explained. Funds were trickling in from his Western benefactors to renovate Timbuktu’s libraries, most of which had fallen into disrepair during the chaotic past two years. As soon as the libraries were ready, Haidara would call upon his couriers again. “We’ll pack all the footlockers into boats and send them back up the Niger River,” he told me with a smile, opening a chest and reverently leafing through piles of restored manuscripts from his own collection. “It won’t be nearly as difficult as bringing them down.”