On the November night in 2008 when the United States elected Barack Obama President, I listened to the coverage on a transistor radio on a rooftop in Timbuktu. (Read more about Timbuktu in National Geographic magazine.)

I sat with a local teacher named Issaka and a businessman named Mohammed atop the small guesthouse Mohammed owned on the outskirts of the city, just a stone's throw from the rolling dunes that mark the southern edge of the Sahara.

Deep into the night we huddled against the desert chill wrapped in quilts, listening to the reports on French radio, discussing politics, and drinking glasses of steaming mint tea dutifully served by Mohammed's ten-year-old nephew Akbar.

To my great surprise, I found Timbuktu, the ancient city in northern Mali whose name is synonymous with the back of beyond, gripped with Obama fever. As I walked through the markets and visited local mosques, several men stopped me to ask if I was American and then gave a thumbs-up and an enthusiastic "Obama!"

A few stalls in the main market sold T-shirts bearing the candidate's visage, alongside others depicting the late rapper Tupac Shakur, French soccer star Zinedine Zidane, and Osama bin Laden. At one point I found myself in a lengthy conversation with an older man, trying to reassure him that Senator John McCain's supporters would not seek to kill Obama if indeed he were to win.

As we sat on the roof, I asked Issaka and Mohammed why people in Timbuktu were so excited by Obama. Did they think he would somehow spur development here? Issaka shook his head as if I were dense. "We are excited because it shows the world that America really believes what it says it believes," he said.

"Even a black-skinned man can be the President. If that is truly possible in America, it makes us ask what is possible in Mali, even in Timbuktu?" Mohammed nodded enthusiastically.

That night it was tempting to think of what might be possible for the legendary city. At first glance, it looked like little more than a sprawling warren of ramshackle mud-brick buildings. Goats wandered the streets. (See Timbuktu pictures.)

Trash was piled in pits dug seemingly at random, and the skeletons of large diesel trucks lay half buried in sand drifts, like beasts of burden that had finally collapsed under the desert's oppressive heat. And yet, even after centuries of decline from its zenith as a wealthy trading hub, Timbuktu in 2008 seemed to be verging on a renaissance of sorts.

Economically, the city was blossoming thanks in part to local historians, who for years had patiently collected troves of lost manuscripts dating back to the Middle Ages, when Timbuktu functioned as an influential center of scholarship.

Now international donors were sending funds to build new state-of-the-art libraries to preserve them, and academics from around the world were arriving every week to study them. The interest in the manuscripts had spurred a building boom in the rest of the city: Two of its landmark mosques were undergoing renovation, a fancy resort hotel was under construction, a new hospital was scheduled to break ground, and increasing numbers of people were moving to the city, building houses and businesses. Moreover, an annual music festival was attracting increasing numbers of foreign tourists, who injected healthy doses of foreign currency into the local economy. (Learn about Mali music.)

Politically, Timbuktu and the surrounding region were enjoying more say in their governance than at anytime since French colonists gained control at the end of the 19th century. Even the long-fractious relations among the city's predominant ethnic groups—the Tuareg, Songhai, and Arabic-speaking Berbiche—seemed to be improving. "We are slowly learning that we need each other," Issaka, a Songhai, said. Mohammed, a Tuareg, nodded, noting that he employed members of all the city's ethnic groups.

To be sure, Timbuktu still had its share of worrisome problems—a long-simmering rebellion among factions of the country's ethnic Tuareg was winding down in the northeastern part of the country, and a radical group of Algerian Islamists calling themselves al Qaeda in the Islamic Maghreb (AQIM) had taken refuge somewhere in the vast wastes of the northern desert.

But Mali's democratically elected President Amadou Toumani Touré had built a close relationship with the United States, which had poured close to a billion dollars into the country and sent American Green Berets to help improve the Malian army's ability to police its desert wilderness.

Up on the roof, with the news services reporting an Obama victory, Mohammed roused a sleeping Akbar and headed off to bed. Issaka and I shook hands and bid good night. "Obama's election is going to inspire us. In four years, I think Timbuktu will be very different," he said to me, smiling. "Maybe Obama will even visit one day."

Amid such optimism, it was impossible then to imagine the cruel twists of fate that would come to pass in four years' time: Mali's government would be violently deposed by a military coup, and two-thirds of its territory would be controlled by al Qaeda-aligned Islamists. Mohammed and Issaka would have to flee the city with their families, and the guesthouse where we had passed the night discussing democracy would become a barracks for al Qaeda fighters. (See a chronology of al Qaeda attacks.)

A Slow Dissolve

After that first trip to Timbuktu, I stayed in touch with Mohammed and Issaka and made several more trips to the city, always staying with Mohammed's family. I got to know people from all sorts of backgrounds and professions, including tour guides, military officers, traders, scholars, manuscript collectors, imams, development workers, Christian missionaries, politicians, camel herders, and local journalists.

I watched Akbar grow from a spidery thin boy into a gangling adolescent. Whenever I arrived in town, he would become my shadow, practicing his English and guiding me through the city's labyrinthine streets and passageways. Back in the States, I would get calls and texts every week from various friends telling me the news and gossip of Timbuktu.

Much of it revolved around the movements of AQIM, which had found refuge in the vast emptiness of Mali's sparsely inhabited and lightly governed desert sometime in the early 2000s. The group had developed a lucrative criminal enterprise kidnapping foreigners—aid workers, tourists, businesspeople, and government representatives—and holding them for ransom. Since 2008, AQIM has abducted 30 Europeans, the most recent a 61-year-old Frenchman just last month. Of these, five have been murdered. (Read why Timbuktu is listed as a World Heritage Site in danger.)

When asked about these incidents, Malian officials would usually point out that the actual kidnappings took place beyond Mali's borders, in neighboring countries—Niger, Mauritania, Algeria—and the hostages were then brought back into Mali and moved among AQIM's desert bases. That made it an international problem, the officials insisted, not just a Mali problem.

But behind the scenes, they would also work quietly to negotiate the hostages' release. Though ransom payments generally were unacknowledged by Malian or foreign officials, locals involved in the negotiations and logistics of freeing several of the hostages told me that large sums of money changed hands.

Various estimates put AQIM's total take in ransoms in the tens of millions of dollars. Meanwhile, the group also began exerting control over the narcotics smuggling routes that pass via West African ports through northern Mali en route to the Mediterranean coast and onward to Europe.

Whenever I pressed Malian politicians about why they didn't mount a campaign to eradicate AQIM from the north, they always reiterated the region's size, roughly the same area as France, and its treacherous terrain. Then they would remind me that the Mali military, with fewer than 6,000 soldiers and only a handful of aircraft, wasn't capable of controlling all of that territory all of the time.

Residents in Timbuktu told me that the military once had mounted a serious campaign to eliminate the group. In 2009, after AQIM assassinated a Malian army officer in the city, the military hastily assembled a heavily armed convoy of soldiers supported by Berbiche militiamen to pursue the group and destroy their desert bases.

But after two weeks of chasing the militants over hundreds of miles of forbidding terrain and several protracted skirmishes and ambushes in which dozens of soldiers and militiamen were killed, including the commander of the expedition, the army gave up.

I interviewed several of the survivors, including Hashem, a militiaman whose brother was killed in one attack. "They knew exactly when we left Timbuktu and every place we stopped for water," he said. "They had many eyes watching us everywhere we went in the desert."

After that failure, the Mali military never made a significant attempt to fight AQIM.

An old imam in Ber, a small desert village north of Timbuktu, described how AQIM had ingratiated itself to the desert tribes, especially the Arabic-speaking Berbiche.

"They take care of the people," he said. "If someone is sick, they bring medicine to the family. If someone is hungry, they bring them food. If someone dies, they give money to the family. That is more than the Mali government has ever done here."

The Libyan Spillover

Long before AQIM arrived in northern Mali and began cultivating its relationships with the Berbiche tribes, Muammar Qaddafi had been building deep relationships with Mali's Tuareg communities, which have long felt disenfranchised by the ruling powers in Bamako. In the 1980s, he broadcast radio appeals to young Tuareg from Mali and Niger to come to Libya to join his military. Thousands responded and were organized in isolated training camps and deployed in special units loyal to Qaddafi personally.

In February 2011, when the Arab Spring came to Libya, Qaddafi deployed these Tuareg units, first against unarmed protestors and then against the subsequent armed uprising. As his regime disintegrated, thousands of Tuareg, fearful of a backlash, began returning to northern Mali and Niger, putting immense pressure on already impoverished communities. As they left, many Tuareg fighters were able to smuggle weapons out of Libya's well-stocked armories. (Read about the Sahara's Tuareg in National Geographic magazine.)

While this was unfolding during the summer of 2011, I visited Timbuktu and interviewed Hamdoon, a Tuareg who had served in Qaddafi's brigades during the 1980s. He told me that as a young man his anger at what he described as the Malian government's refusal to develop the Tuareg-dominated north of the country had prompted him to travel to Libya and enlist in the Tuareg brigades. He saw his first combat during Libya's invasion of Chad.

Hamdoon said he realized Qaddafi's true intentions when Tuareg units were ordered into the heaviest fighting on front lines while Libyan units brought up the rear. "He was using us," he said.

In 1990 Hamdoon got word that Tuareg groups were rebelling against the Malian government and returned home to join the fight. Five years later, as part of the peace accords that ended the rebellion, he, along with many of his fellow Tuareg fighters, were absorbed into the Malian army, where he has since risen to the rank of a mid-level officer.

His ability to speak English had allowed him to train with U.S. Special Forces troops that periodically arrived to train Malian soldiers in the north, and his language was peppered with American slang and profanities he had picked up over the years.

When I saw him in 2011, Hamdoon said he was very worried about what was coming. We met in a hotel just outside Timbuktu's city limits. Almost no foreigners dared come to the north these days, and its French owner had abandoned the hotel. We sat on chaise lounges next to an empty swimming pool. "You will see, the war is coming to Mali next," he said gravely.

He used the frayed end of his turban to wipe the sweat from his weary face. He explained that the Tuareg fleeing Libya had left behind a standard of living almost unimaginable in northern Mali. "Those dudes had free houses with running water. They had schools for their children—good schools. Medical care was free—good medical care. And they had good roads."

Roads? I asked. "Roads are everything," he said. "They allow people to make business. There is no development without roads." Building them, he said, also showed respect by the government toward the people who live in a region. "The lack of roads in northern Mali is like the government saying 'f**k you' to us."

A Downward Spiral

Six months after my conversation with Hamdoon, a Tuareg rebel group began attacking government military bases in northern Mali. Most disturbing was the fact that they appeared to be supported by AQIM and other Islamist factions.

Over the next few months, the Malian government's inept response to the rebellion and the high number of army casualties led to a coup by mid-level military officers, who said they could no longer stand by and watch their comrades, underequipped and poorly supported, be sent to their deaths in the north. As Bamako echoed with gunfire and confusion reigned over who controlled the government, the Tuareg rebels and the Islamists began to move on key northern cities and military bases.

Last April I was awoken at home in the middle of the night by a telephone call from Akbar. The reception was poor, but I could make out his unmistakable adolescent voice through the static. "The rebels are coming. We can hear the big voice of their guns close by in the desert."

In the previous few days, I had spoken with Mohammed about his plans to leave the city. The first thing he had done was to hide his most reliable vehicle, an aging Land Cruiser, in a family member's sheep kraal.

He removed the battery cable and the starter motor because, as he explained, in times of crisis vehicles are the first things stolen. He then had traded his prized television, a recent purchase, for one of the last available barrels of gasoline in the city.

"When we heard the rebels were going to take the city, the government soldiers got into their quatre-quatres (four-wheel-drives) and drove south. "They abandoned us," he said before we hung up. "The country has abandoned us."

In the following weeks, AQIM—joined by two like-minded factions, Ansar Dine and the Movement for Oneness and Jihad in West Africa—were able to expel Tuareg rebel leaders who refused to agree to an Islamist agenda, effectively hijacking the rebellion.

"It came down to money," Sidi Al Kafru, a local journalist in Timbuktu, told me by phone. "AQIM has more money to buy weapons and enough food and petrol to give to local people so they wouldn't protest too much."

Behind the Black Curtain

Since then, locals say, the Islamists have enforced a Taliban-style interpretation of sharia. Among the first orders of their occupation was the destruction of several tombs of venerated Timbuktu scholars who were deemed "un-Islamic" along with other "blasphemous" landmarks. They broke down the sealed holy inner door of the 15th-century Sidi Yahya Mosque.

According to tradition, its opening would bring the end of the world. They ransacked the brand-new, state-of-the-art Ahmed Baba Institute, built with funds donated by South Africa to house one of the city's largest collections of ancient manuscripts, because its appearance was considered too modern.

Ansar Dine took control of the city's radio stations, replacing news and music with readings from the Koran. They decreed that anyone caught smoking, drinking alcohol, listening to music, or dancing would be publically whipped. Girls were barred from attending schools, and women were obligated to wear loose black burkas. In one reported case, a pregnant woman was denied access to the hospital because she was wearing a burka deemed too revealing. She delivered her baby on the steps outside the hospital.

In September, locals described how Islamists punished a thief by amputating his hand. Similar accounts are coming from other cities in the north. In Aguelhoc, a village northeast of Timbuktu, eyewitnesses reported that an unwed couple was stoned to death.

Adding to the tension are reports that the Islamists have been recruiting boys, especially those from poor families, for military training. Mohammed recounted the story of one Tuareg friend whose 12-year-old son had agreed to do manual labor at the Islamist base in the center of the city on the promise that his family would receive a bag of rice. Later the boy was seen practicing rifle drills with other recruits, and word got back to his father.

The worried man went to the military base and asked to see the Islamist commander. He politely explained that his son was just a boy and did not understand what he was committing himself to and that he was needed at home to help the family. The commander replied that the boy had made a "holy decision" and that he was performing what was required of him by Islam and that he should be proud of his son. "You may have his body when he has fulfilled his duty to Allah," the commander said.

Meanwhile, friends remaining inside Timbuktu describe the arrival of dozens of foreign fighters from several African nations—Algerians, Mauritanians, Senegalese, Nigerians—but also Pakistanis, Afghans, and even a Frenchman and an Englishman. The city has been fortified with large guns and a few armored vehicles, which locals say come from Libya. "They are preparing for a big fight," a journalist in the city told me. "They expect the West to attack. They are nervous."

While the Islamists have consolidated their hold on northern Mali, the international community has dithered about how to respond to the crisis. Some policy analysts have argued that Mali must first resolve the coup and hold elections to bring a legitimate government into power before any military campaign can be undertaken to oust al Qaeda and its allies.

But others point out that free and fair elections can't be held as long as two-thirds of the country's territory is held hostage. Consensus seems to have emerged that a coalition force of African troops will eventually be deployed under the auspices of the Economic Community of West African States (ECOWAS) and the African Union, but how those forces will be trained to fight in the desert, how they will be supported logistically during the campaign, and who will pay for them remains to be determined.

As all of this was being debated, I called Mohammed. His family had escaped to a refugee camp in Mauritania, and he had traveled to Bamako to pick up medicine for Akbar, who suffered a serious bout of malaria that left him experiencing seizures. While in the Malian capital, he was closely monitoring the political developments.

"They are doing it the African way," he said, referring to the gaggle of politicians, military officers, and international representatives. His voice was terse with frustration. "Everyone is going to lots of meetings. They all want to be the leader. They all want money first. [A military intervention] will not happen soon."

Last month, on Election Day in the U.S., I called Issaka, who himself had relocated to Bamako. He described how the capital, swollen with refugees from the north, remains tense with uncertainty and rife with rumors.

I reminded him of how Obama's election had stirred jubilance among Timbuktu residents four years before. He laughed. "That was a long time ago." But then in a wistful voice added, "We need Obama now more than ever."