TUNIS — Four years ago, thousands of Tunisian jihadists began flowing to the battlefields of Iraq, Libya and Syria to join the Islamic State and al-Qaeda — more than from any other nationality. Ever since, Tunisian and Western authorities have feared their return and the possible chaos that could follow.
So far, those fears haven’t materialized, according to Tunisian authorities, Western diplomats and regional analysts.
Instead, the Islamic State and al-Qaeda are recruiting a new generation of locals to stage terrorist attacks at home, including one in July near the Algerian border that left six national guardsmen dead.
“This is primarily homegrown,” said Matt Herbert, a partner at Maharbal, a Tunis-based security consulting firm. “The majority of Tunisians who survived Libya and Syria have not returned.”
The continuing local recruitment of militants highlights the challenges facing Tunisia, the only nation to emerge as a democracy after the 2011 populist revolts across the region that became known as the Arab Spring. Although the ideological appeal of the Islamic State and al-Qaeda appears to have shrunk in many parts of the country, diplomats and analysts say a post-revolution era of political, economic and social turmoil is still breeding resentment, especially among Tunisia’s youth.
Frustration over a lack of economic opportunities and social mobility has driven more than 3,000 Tunisians to leave for Europe this year, more than from any other nationality, according to the United Nations’ migration agency. These same factors have caused others to join extremist groups, especially in areas long neglected by the government.
“Socioeconomic crises are the best fuel either for illegal migration or, in worst-case scenarios, for feeding terrorism,” said Patrice Bergamini, the European Union’s ambassador to Tunisia.
Much of the recruitment is taking place in Tunisia’s impoverished southwestern mountains along the border with Algeria. Both the Islamic State, also known as ISIS, and al-Qaeda in the Islamic Maghreb, the terrorist network’s branch in North and West Africa, have affiliates operating along the border.
Although the extremists are said to be mostly Tunisians, they also include Algerians, West Africans and Libyans, regional analysts said. Only about 15 to 20 Tunisians are thought to be returnees from Libya and Syria, they added.
At least 5,500 Tunisians have traveled in recent years to Iraq, Libya and Syria to join the Islamic State and al-Qaeda, according to U.N. estimates.
Many of the Tunisians who went to Libya died in late 2016 in the fight to retake Sirte, the capital of the Islamic State’s so-called caliphate in North Africa, and in the battle for the Tunisian border town of Ben Guerdane, analysts said.
And many of the extremists who went to Syria and Iraq are thought to have died fighting there. Survivors of those battles are thought to be among a pocket of Islamic State militants holding out in eastern Syria or held in Syrian prisons. Some are probably in hiding. Others slipped away to Libya to join the Islamic State affiliate there, or may have joined a branch in Egypt’s northern Sinai Peninsula.
As many as 800 fighters have returned to Tunisia, and the vast majority of them are incarcerated around the country.
The extremists now active in Tunisia, some analysts say, are using the country as a staging ground for attacks on Algeria, which has fought a long confrontation with al-Qaeda and, more recently, a new Islamic State branch.
“Tunisia is the land of recruitment,” said Michael Bechir Ayari, Tunisia senior analyst for the International Crisis Group.
Others say Tunisia itself remains a target because of the government’s relatively liberal views on Islam, women and freedom of expression.
In 2015, Tunisian gunmen with the Islamic State attacked the resort town of Sousse and the famed Bardo Museum in the capital, killing scores of people, mostly foreign tourists. The following year, more Tunisians belonging to the Islamic State entered from Libya and tried to seize Ben Guerdane before Tunisian security forces repelled them.
Since then, the Islamic State and al-Qaeda have carried out more attacks in Tunisia, but none as catastrophic. Today, an estimated 200 militants belonging to either the Islamic State or al-Qaeda are operating in the mountains, although the number of sympathizers is unknown, analysts said.
The attack in July near the Algerian border illustrated the militants’ continuing ambitions. The national guard vehicles were on patrol in a remote mountainous patch near the town of Jendouba when the militants, hidden in the bush, threw a grenade and a gunfight ensued.
“It was a treacherous ambush,” said Omar Benaissi, a top local official in Ghardimaou, the impoverished region where the attack happened. “The six were killed in the moment the attack happened.”
Residents and officials suspected that the militants may have been tipped off to the convoy by local supporters. Al-Qaeda’s local branch asserted responsibility for the attack, which analysts say was intended to show that the militants are still a force and to use for recruitment.
“The groups still operating out there in the mountains out west have a lot of skill,” Herbert said. “They seem to have grown in size over the past couple of years. They have a lot of resilience to withstanding Tunisian attempts to end this conflict.”
Hatem Hwawi, a teacher and blogger in Jendouba, said most of the local residents lead hardscrabble lives and resent the government, making them susceptible to militant appeals.
“They are miserable and can be easily recruited by the terrorists,” he said. “The Tunisian authorities are creating a fertile soil for terrorists, either by marginalizing the security forces or marginalizing the people economically.”
Hwawi, who said he helped carry the wounded soldiers into the hospital, described them as ill-equipped, with guns and shoes in poor condition.
Tunisian authorities say they have made progress in tackling the local militancy, noting the decrease in attacks nationwide. The United States has provided tens of millions of dollars to enhance security on the Libyan border.
Security analysts give high marks to the nation’s U.S.-trained counterterrorism forces for gathering intelligence and for penetrating and dismantling cells. But the analysts are concerned about non-elite forces, such as police and border guards, who have less training and are more corruptible.
Analysts also are increasingly concerned about the potential for radicalization in Tunisia’s prisons, where many extremists are kept in cells with common criminals.
“It is definitely a worry, since there is a huge population of individuals in overcrowded prisons planning their next strategic moves for whenever they are released from prison,” said Aaron Zelin, an expert on jihadist groups with the Washington Institute for Near East Policy and author of a forthcoming book on the history of Tunisian jihadism.
The Tunisian state, he added, does not have adequate rehabilitation or reintegration programs for former militants. “So it is likely if they are released, they would just revert back to their old ways with ISIS or al-Qaeda, depending on their affiliation when they went in.”