They were nurturing a viper. The warlord, as the Algerians well knew, was the leader of one of the militant Islamist groups holding northern Mali captive. That was not a deal-breaker, they reasoned. To the contrary, having tight connections with a powerful militant across the border, much as Pakistan does in Afghanistan, could protect their interests.
But instead of ensuring that the conflict remained outside their country, a longstanding imperative of the Algerians, the warlord, Iyad Ag Ghali, ended up bringing it right to them. His forces made a sudden push toward the Malian capital in January, enraging his Algerian patrons, bringing on a French military intervention and ultimately giving extremists a rallying cry to seize an Algerian gas field, leading to the deaths of at least 38 hostages.
“They told me they didn’t want to have anything more to do with me,” recalled Mr. Ag Ghali’s representative in Algeria, Mohamed Ag Aharib. The militant offensive in Mali, which set off the deadly chain of events, “really shocked the Algerians,” he said.
For months, the United States and French officials upheld Algeria, with its counterterrorism know-how and the biggest military budget in Africa, as the linchpin in resolving the threat of Islamist extremism in Mali.
But Algeria helped maintain its dominance of the Sahara by playing favorites among the various armed groups plaguing its neighbor, a policy that backfired tragically last month and failed to achieve its most basic aim: to push the problem away.
The tangled web of allies and interests across the volatile region underscore the unique difficulties the French and the African forces could face as they begin to wrest control of Mali’s north from the jihadists who have held sway there for almost a year.
Chasing a few hundred foreign fighters inspired by religious zeal from the vast, trackless area would be challenge enough. But the forces shaping the conflict are far more complicated than that, driven by personal ambitions, old rivalries, tribal politics, the relationship between militants and states, and even the fight for control of the lucrative drug trade.
All of these power struggles have helped shape the fate of the region — and they will almost surely continue long after the battle to recapture the north is over.
“We have two kinds of logic looking at these organizations and these people,” Georg Klute, a professor at the University of Bayreuth, Germany, said of the mosaic of rebels, bandits and Islamist militants in the region. “One is the ideology. The other is the local logic.”
Mr. Ag Ghali’s own evolution is a case in point. A charismatic Tuareg aristocrat who for years had been alternatively leading rebellions in the desert and helping tamp them down, he once functioned as a liaison for European governments seeking to pay huge ransoms to release kidnapped tourists. He was even named Mali’s consul general in Jiddah, Saudi Arabia, from 2007 to 2009.
“He has been on both sides of everything,” said Gregory Mann, an associate professor of African history at Columbia University.
Even Mr. Ag Ghali’s pivotal decision to form Ansar Dine, one of the Islamist groups that seized northern Mali last year, stemmed as much from local politics and personal ambition as his newfound devotion to enforcing a puritanical form of Islam.
In late 2011, scholars say, he made a bid to become head of his Tuareg tribe — a position that would have put him at the forefront of northern Mali’s struggle for autonomy. When he was rebuffed, Mr. Ag Ghali struck out on his own and formed Ansar Dine, branding it as a religiously inspired alternative to the more secular Tuaregs.
Though Algeria is brutally intolerant of Islamist militants — having fought a bloody war against them in the 1990s that ultimately led to the creation of Al Qaeda in the Islamic Maghreb — it found common ground with Mr. Ag Ghali. Ansar Dine may have been religious, but its ambitions did not seem to challenge Algeria directly. By contrast, the Tuaregs, newly fueled with nationalists returning from Libya, were demanding independence, frightening Algeria that its own minorities might become inspired as well.
The Algerians gambled that “Ansar Dine could be a counterweight to these attempts to erecting an independent Tuareg state,” Professor Klute said, so “they closed their eyes when Ansar Dine crossed the border” for “gas, cars, spare parts.”
All through the fall of 2012, as Mr. Ag Ghali’s fighters lorded over civilians in northern Mali and the world made plans to oust them and other militants by force, his men were in Algiers negotiating with the government, promising peace and signing agreements. This continued despite ample evidence that Mr. Ag Ghali had become a committed ally of Al Qaeda in Islamic Maghreb — Algeria’s sworn enemy — receiving arms, weapons, men and other material from the group.
“The ties were very strong,” Mr. Aharib, Mr. Ag Ghali’s representative here, said. “They shared the spoils. They worked side-by-side.”
Rather than denouncing Ansar Dine, the Algerians appeared intent on preserving the alliance, hoping to pry it away from the religious extremists and portray it as a solution to the crisis in Mali.
“A man of his word, a man one can trust,” a retired senior Algerian diplomat said of Mr. Ag Ghali in a recent interview.
“A calm and polite man, who knows what he wants,” echoed a retired ranking officer in the Algerian military.
Algerian officials publicly scoffed at fears that northern Mali had been lost to Islamist militancy, and on Dec. 23, Algeria’s foreign minister hailed a peace deal involving Ansar Dine as a “very encouraging step.” The day after, however, an Ansar Dine spokesman in Timbuktu announced that the group would destroy all of the city’s remaining aboveground mausoleums — sacred to the city’s residents — in the name of Allah.
But then Mr. Ag Ghali did not stick to his scripted role. In January, he joined the other jihadists in pushing farther south into Mali, precipitating the French military intervention that Algeria wanted to avoid.
“He decided this with his other jihadist comrades,” Mr. Aharib said of the push into southern Mali. It led to a break within the group, he said: “This was too much for us. We didn’t look favorably on this at all.”
The consequences unfolded quickly. Algerian citizens were enraged that their government allowed the French to use its airspace to carry out the military campaign. Within days, Islamist extremists stormed a remote gas field in the Algerian desert, calling it vengeance for the French assault and Algeria’s compliance with it. At least 38 hostages were killed. The image of Algeria as the regional powerhouse that had conquered terrorism was suddenly, perhaps irrevocably, undermined.
“This is really a failure of their strategy,” said Anouar Boukhars, an expert on North Africa at the Carnegie Endowment for International Peace. “It was flawed from the get-go.”
In the aftermath, Mr. Aharib and some others in Ansar Dine announced last week that they had split off from the group because they were “moderates.” For now, Mr. Aharib has saved his room at the hotel in Algiers. With the Islamists of northern Mali in full retreat as a result of the French military campaign, Mr. Ag Ghali is on the run somewhere in the desert.
Yet the Algerians have not given up hope of working with Ansar Dine, or at least some iteration of it.
“I’m sure Ansar Dine can be brought around,” said a senior Algerian official, the day before Mr. Aharib’s announcement. “There must be a renewal of dialogue.”
Adam Nossiter reported from Algiers, and Neil MacFarquhar from New York. Hadjer Guenanfa contributed reporting from Algiers.