Several factors have combined to create a fertile breeding ground for jihadist violence in Tunisia where gunmen mowed down 21 people in a high-profile attack on its national museum, analysts say.
They say economic and social woes on top of political upheavals since a 2011 revolution which ousted longtime strongman Zine El Abidine Ben Ali have disorientated the country's youth.
Tunisia has contributed the largest number of citizens to radical movements such as the Islamic State (IS) jihadist group.
Other factors have also contributed: a fledgling democracy, proximity to the political and security mayhem in neighboring Libya, and a lack of Muslim religious training that contributed to the import of Salafist ideology since the 1980s.
IS claimed responsibility for Wednesday's attack in which 20 foreign tourists and a policeman at the renowned Bardo museum in Tunisia were killed before the two assailants were themselves gunned down.
Tunisia says 3,000 of its citizens have joined the ranks of jihadist groups in Syria, Iraq and Libya, while as many as 9,000 would-be recruits in a country with an 11-million population and secular tradition have been barred from travel abroad.
"The classic explanation is that of social despair which, little by little, leads to forms of radicalization," said Omeyya Naoufel Seddik of the Centre for Humanitarian Dialogue, an NGO promoting dialogue to resolve conflicts.
"There have been surprising cases, of late, of Tunisians joining the IS as a path to social advancement. The idea has been circulating that it can offer a higher standard of living than many other places," he said.
With modest 2.5 percent growth and a graduate unemployment rate of 30 percent in a country where more than half the population is aged under 25, the new government which emerged from elections last year has prioritized both the economy and security.
"But the young people involved (with jihadist movements) don't all come from disadvantaged backgrounds," said Soumaya Belhaj, a lecturer at the University of Tunis, adding that there is no typical profile.
She spoke of "a convergence between personal frailties and an environment that favors a drift towards (Islamic) fundamentalism", with "all the upheavals since 2011 making some people search a life project".
'All the ingredients'
Ridha Sfar, who until the start of 2015 was number two at the interior ministry, stressed the role played by Tunisia's social and political crises but also the proximity of a "collapsing state" in Libya.
"We have all the ingredients for the development of jihadist movements: the manpower, the ideology, the weapons and the money," he said.
The two Bardo assailants had received military training in Libya, according to Tunisian authorities.
A deputy speaker of parliament, Abdelfattah Mourou, a co-founder of the moderate Islamist movement Ennahda, warned of a return to the Ben Ali era of the late 1980s when Islamists were rounded up in droves.
"That created a vacuum that was filled by Gulf (satellite) channels and Wahhabism," the strict form of Sunni Islam practised in Saudi Arabia, he said.
The jihadist phenomenon is not something new in Tunisia, from which large numbers of anti-US militants joined fighting in Afghanistan and Iraq in the 2000s.
But it has accelerated since the revolution.
For the NGO's Seddik, "we must understand that for a society in flux after decades of iron fist rule, it's only natural for there to be some form of radicalization, especially among the young".
"There has to be a way for them to express themselves in a non-violent manner… This can only happen through real dialogue between the authorities and civil society," he said.
Belhaj, the academic, said "the role of politicians is to outline what project for society we can offer to these youths… For the time being, there's nothing."