The Grand Mosque of Niamey, built with Libyan government funding in the 1970s, is a beaming adobe with a prism of latticed archways capped with a brilliant green dome, glittering and unscathed after decades under the Sahelian sunlight and dust.

The Grand Mosque of Niamey. Armin Rosen/Business Insider

The Grand Mosque dominates a vast open expanse: It’s one of the only major civic buildings in the Nigerien capital that isn’t behind a high wall or a security cordon. On a Friday afternoon, mosquegoers bow in prayer all the way out to the complex’s distant edges.

The mosque is a respite in a city where cows sometimes wander into traffic and the skeletons of broken-down cars rot in dusty median strips. Its elegance and openness are almost a deliberate commentary on Niamey’s other landmarks: colorless ministries compound, boxy high-rises, and aging hotels overlooking the Niger River, with their dim lobbies and cloudy swimming pools.

The Libyan Investment Authority (LIA) is suing Goldman and Société Générale over losses sustained in the Gaddafi era. EPA Libyan dictator Muammar Gaddafi, who spent 42 years brutalizing his own people before an angry mob lynched him in a drainage ditch in October 2011, built the most impressive, and the most dignified, structure in town.

He also funded and fomented rebellion within Niger, openly encouraged the overthrow of Nigerien leaders, and even staked claims to over 11,500 square miles (30,000 square kilometers) of Nigerien territory, displaying the same kind of meddlesome and seemingly arbitrary behavior that characterized his relationship with countries across Africa.

But there was a larger strategy at play. Gaddafi filled vacuums in ways that ensured no one could ever really fill them again, or at least not quickly or easily, and not to the same degree. He created vacuums only he could fill.

He manipulated the dreams of downtrodden populations, drafting them into his self-serving and pseudo-imperial schemes. Above all, Gaddafi created a lucrative, trans-Saharan economy of violence to conjure the illusion of his own indispensability.

As the chaos in Mali and Libya, and the predictable and deeply misguided nostalgia for Gaddafi’s rule in some circles both demonstrate, this accomplishment has comfortably outlived him.

Compared to Mali and Libya, it’s much safer to assess Gaddafi’s dubious legacy in Agadez, northeastern Niger’s centuries-old capital of trans-Saharan trade, 600 miles and 16 harrowing hours up the road from Niamey.

Famed for its 500-year-old mud brick mosque and nearby Sultan’s palace, Agadez is a day’s drive from the sand-dune oceans of the Grand Erg of Tenere and closer to the foothills of the Air Mountains, a micro-climatic island just wet enough to support grape harvests in a vast desert.

Agadez was a tourism spot, but that was before the collapse of Libya and its series of direct and indirect consequences: the jihadist surge into northern Mali, the uptick in activity from Al Qaeda in the Islamic Maghreb, the militant free-for-all in Saharan Libya, and the opening of a significant arms-trafficking corridor in northern Niger.

The minaret of the 500-year-old Grand Mosque in Agadez, a UNESCO World Heritage Site. Armin Rosen/Business Insider

Agadez is now considered a “red zone” by the French government, which has troops deployed in eastern Niger near the Libyan border. In 2013, 23 people were killed when an Al Qaeda-linked group attacked a Nigerien army base in the city, which has luckily remained Agadez's only major terrorist incident.

According to the Historical Dictionary of Niger, Gaddafi often traveled to Agadez to celebrate Maoulid, the Sufi commemoration of the birth of the Prophet Muhammad.

But his affinity for the place wasn’t primarily spiritual: Agadez is also one of the centers of a historically powerful Nigerien Tuareg community that’s long struggled to reach an accommodation with the southern-dominated elite in Niamey.

The Tuareg are a transnational ethnic group spread across thousands of miles of Saharan wilderness and are often romanticized for their desert combat and survival skills. They're 10% of Niger's population, herders and desert traders who were often systematically excluded from both the military and the positions of power.

As in neighboring Mali, many Nigerien Tuareg chafed against the reality of a far-off capital wishing to impose the powers of a centralized, bureaucratic state on a desert that the Tuareg had proudly dominated for centuries — a maddening vastness where the elements are almost engineered to strip away any pretense of status or authority.

The desert near Agadez. Armin Rosen/Business Insider Gaddafi tried to turn this local discontent to his advantage, hosting and patronizing armed Nigerien exile groups in the mid-'80s.

As Peter Dorrie explained in a 2012 article in World Politics Review, Gaddafi "trained scores of young Tuareg in military camps in Libya, ostensibly to prepare them for rebellion in their home countries."

This allowed him to triangulate policy during Tuareg uprisings in Niger in the mid-'90s and late 2000s: Gadhafi "contributed to ending the insurgencies by buying off many of the armed groups’ leaders and fighters, offering Tuareg commanders refuge and high-ranking posts in the Libyan army and inviting rank-and-file fighters to Libya or compensating them with cold hard cash for their 'services,'" Dorrie writes.

And Gaddafi had success in recruiting Tuareg as hired guns.

In Agadez, Business Insider met a man named Mohammad, a lifelong desert entrepreneur who breeds camels and drives tanker trucks of water to artisanal gold miners deep in the Sahara.

In the mid-'80s, he spent three months fighting in Chad as part of a Tuareg mercenary force the dictator mobilized during his invasion of that country, part of Gaddafi's quixotic and inevitably thwarted bid to annex large sections of the central Sahara.

Mohammad had a cynical view of Gaddafi, who was a tactical and inconsistent supporter of Tuareg nationalism.

“He was just doing politics with the Tuareg,” he said. “We thought we'd get a country in return for fighting for him, but we got nothing.”

In turn, Gaddafi had an inevitably cynical view of the Nigerien Tuareg. During a Tuareg revolt in northern Niger in 2007, Gaddafi proclaimed himself "Leader of the Tuareg Sultans." The next year, he demonstrated his influence over the insurgency by securing the release of 25 people that a Nigerien Tuareg militia group was holding hostage.

Business Insider also met a prominent Tuareg leader who claimed to have traveled to Tripoli during that revolt, where he says Gaddafi personally gave him two brand-new Volvos and cash — an inducement to push the insurrectionists toward a peaceful settlement, and a potent reminder of his ability to influence his neighbor's affairs.

Gaddafi used the Tuareg as mercenaries inside of Libya. And beyond his country’s borders, they became an instrument for projecting power into neighboring countries and leveraging regional fissures.

None of this was enough to turn the Nigerien state and the Gaddafi regime into permanent enemies. Gaddafi constantly shifted policy toward his southern neighbor, calculating that he was simply too powerful for vulnerable regional states to oppose.

In the '90s, Niger was one of the founding members of Gaddafi's Community of Sahel-Saharan Countries, which helped charter a major Nigerien bank that is still in operation. These investments insured that relations didn't reach a crisis point. In 1998, Nigerien leader Ibrahim Bare Mainassara even broke an international air-travel embargo to visit the Libyan tyrant in Tripoli.

Through this decades-long give-and-take strategy of simultaneous patronage and troublemaking, Gaddafi connected his regime's fate to that of his neighboring countries.

A wristwatch featuring a photograph of the late Libyan leader Muammar Gaddafi in Agadez, September 23, 2013. Neli previously worked as a servant in Gaddafi's son's Saadi's house in Tripoli. Picture taken September 23, 2013. REUTERS/Joe Penney

Weaponry, and the regime's former hired guns, flooded Mali after the dictator’s ouster, contributing to the slow-building security and political crisis that culminated in the brief jihadist takeover of the country’s desert north in 2012. Today, many in northern Niger see consequences of Gaddafi's fall inside their own country.

“Now that Libya has fallen, everything has become harder,” Kamil Khamed, a National Assembly candidate from the mostly Tuareg city of Tchintabaraden, told Business Insider.

“People used to work in Libya and send money back to their families. Today, there’s no chance to go to Libya.”

Musa Kaka, a Niamey-based journalist with years of experience reporting in the north of the country, agrees.

“The death of Gaddafi was a bad thing for the countries bordering Libya,” he told Business Insider.

“It is because of the crisis in Libya that Niger has focused so much on security, by sending soldiers around the front line with Libya, or to Mali,” where Niger has contributed to a UN peacekeeping force, Kaka said.

“We are between two fires. It’s very serious.”

A nomadic Tuareg settlement near In-Gall, Niger. Armin Rosen/Business Insider Today, Libya has two rival governments, and both Al Qaeda and ISIS affiliates operate in the country.

As Khamed alluded to, the collapse of the Libyan state denied Nigeriens of a top migration destination. According to a report by the Rand Corporation, between 80,000 and 160,000 Nigeriens living in Libya returned to their home country after Gaddafi’s overthrow.

The collapse of Libya closed off an economic escape valve: “Lots of young people went to Libya to find a job,” Sidi Mamane, the mayor of the northern Nigerien city of In-Gall, told Business Insider. “Now if they go, it’s to fight for one of the militias.”

At the same time, Gaddafi’s departure opened up certain Libya-related economic opportunities for northern Nigeriens, since the lack of a strong, centralized state on the other side of the Libyan border allows for the flourishing of contraband cross-Saharan trade.

“When Gaddafi collapsed, smuggling increased,” says Mamane. “There’s no control between the Mediterranean and the north of Niger.”

Most notable, at least for the US and its European partners, has been the trade in transporting human beings across the desert. Without a government to police immigration, the northern Libyan coast has become a common departure point for migrants crossing the Mediterranean, and it can be reached from Agadez in a matter of days.

Migrants scramble to get onto Migrant Offshore Aid Station (MOAS) rescue boats launched from the MOAS ship Phoenix after they jumped from an overloaded wooden boat during a rescue operation 10.5 miles off the coast of Libya, August 6, 2015. REUTERS/Darrin Zammit Lupi

Niger is in a visa union with a number of other West African states. Would-be migrants can legally travel to Agadez, where law enforcement is lax and transportation options are plentiful. Beyond Agadez, any remaining concept of legality breaks down. There’s no state to enforce immigration or trade in Libya.

And while the Nigerien government deployed additional soldiers to prop up the state’s presence in the country’s northeastern desert after Libya's collapse, as Musa Kaka noted, the military still lacks the aerial or forward deployment capabilities needed to effectively police the frontier.

Illicit cross-desert trade encounters very little official hindrance when weapons smuggling or terrorism aren’t directly involved. According to multiple sources that Business Insider spoke with in Agadez, a migrant convoy leaves the desert city in the pre-dawn hours each Monday, not long after the departure of a weekly military convoy that resupplies remote Saharan army bases.

The migrant convoy benefits from the perceived safety of following a military column. And it leaves on a predictable schedule that's one of the city’s worst-kept secrets.

As Agadez Regional Council president Mohammed Anacko explained to Business Insider, controlling the post-Gaddafi spike in cross-desert smuggling would have ground-level costs, especially since security concerns have all but wiped out tourism.

“The migrants took the place of tourism as an industry,” Anacko said. “Unemployed young people with cars used to be tourism guides. Now, they transport migrants.”

To halt migration and other contraband desert trade, Anacko said, international partners have to “propose something for unemployed young men who have cars and know the desert. One young man with a car can help all of his family with just one trip.”

The highway between Agadez and Arlit, in northern Niger. Armin Rosen/Business Insider It’s a security imperative to control trade within a vast and potentially unstable desert with a suspected Al Qaeda presence. At the same time, it’s a social and economic imperative to keep young people busy and employed.

This tension might get worse in the coming years, even if Libya stabilizes. Sidi Mamane, the mayor of In-Gall, said that the nomadic life that many local Tuareg are used to is becoming less tenable, thanks to population growth and a plunge in the local water table.

“In the future, there will be no more nomadism. People will move to the cities and they’ll stay there,” says Mamane.

Some former nomads will likely settle in established and already-growing population centers like Agadez. They’ll be forced to adapt to an urban setting where the most promising economic opportunities are products of the lawlessness of the desert lying just beyond the city’s already expanding outskirts.

A future, unitary Libya would form within this context of endangered nomadism, lingering desert militarism, and un-policed trans-Saharan trade.

It won’t look like Gaddafi’s strong state, and the idea that the whims of a single man or madman could fill the Saharan vacuum may have died with the Libyan dictator.

Libyans — the primary victims of Gaddafi’s regime — didn’t want their 42-year-old status quo to continue.

But the end of Gaddafi's regime, and the prolonged period of turmoil that’s followed, have had complicated reverberations in Niger.

The need to adapt to the post-Gaddafi conditions may be the dictator’s most consequential legacy in Niger, something that could prove far more tangible to the life of the country than a single mosque in a distant capital city.

Armin Rosen reported from Niger on a fellowship from the International Reporting Project.