Praised as a model of Arab Spring progress, Tunisiahas finally been drawn onto the global jihadi battlefield after Islamist militants gunned down foreign tourists in a brazen assault at the heart of the capital.
The storming of the Bardo museum inside the heavily guarded parliament compound was more deadly evidence Islamist militants are turning to North Africa as a new front beyond their main battlegrounds in Iraq and Syria.
Libyan and Tunisian jihadists have streamed to the ranks of Islamic State and other militant groups in Syria and Iraq. That flow is reversing with experienced North African fighters returning to target their homelands.
In Libya, where two rival governments are battling for control and armed groups flourish on the streets, militants returning from Syria and linked to Islamic State have established a new outpost. Washington believes 3,000 fighters loyal to Islamic State are fighting there, including 300 returned from Syria or Iraq.
Since the start of this year, fighters in Libya proclaiming loyalty to Islamic State have beheaded Egyptian Christians, stormed a Tripoli hotel seeking foreigners to kill and overrun three oilfields kidnapping 10 expatriate oil workers.
Neighbouring Tunisia has until now been mostly peaceful. It was the birthplace of the "Arab Spring" protests that swept the region at the end of 2010 and start of 2011, and four years later it is that era's only success story.
Since a popular revolt toppled autocrat Zine El-Abidine Ben Ali, Tunisia enjoys free elections, a new constitution and politics that have seen compromise without the civil wars or widespread violence seen in Egypt, Libya, Syria or Yemen.
But although it has seen little armed militancy at home, Tunisia has become a big exporter of fighters to wars elsewhere. More than 3,000 Tunisians have left to fight in Syria and Iraq, and the government estimates around 500 have since returned.
"There are many Tunisians with Islamic State in Syria and Iraq, but also there are Tunisian members of Islamic State returning back here too," said Rafik Chelli, a senior interior ministry official.
Attacks like Bardo are low cost, logistically simple raids by fighters motivated either by Islamic State or al Qaeda recruitment to inflict maximum damage and spread the extremist message, said Algerian security analyst Khelifa Rekibi.
"This will motivate other groups to imitate the attack or increase recruitment either to ISIS or al Qaeda," he said. "The terrorism is becoming more professional and the risk greater."
Militants in North Africa have been drawn to economic targets like Libya's oil fields and Algeria's Amenas gas plant, where 40 oil workers were killed two years ago in an assault by fighters. While Tunisia does not have much oil or gas, killing foreign visitors hurts its vital economic motor, tourism.
"The possible introduction of IS operations in Tunisia could be the start of renewed targeting of civilians in the region, and also push al Qaeda-linked groups who have for some time targeted largely political and military targets back toward more overt attacks against civilians," said Andrew Lebovich, a North African security expert in New York.
Whether the museum attackers were followers of Islamic State's leader, Abu Bakr al-Baghdadi, much less directed by the group, is still not clear. Claims of responsibility were murky. Islamic State called the two militants "knights", while a social media site tied to an al Qaeda-associated group also carried details of the assault.
Islamic State, also known as ISIS or ISIL, split off from al Qaeda and shares its violent Salafist Sunni Muslim ideology. After seizing the northern Iraqi city of Mosul last year, Baghdadi proclaimed a "caliphate" to rule over all Muslims.
While some militant groups that once stood with al Qaeda have embraced the caliphate to take on the Islamic State banner, the central al Qaeda leadership rejects it.
Militants in Tunisia have mainly allied with Ansar al Sharia – the group Washington blames for the deadly 2012 attack on its diplomatic mission in Benghazi, eastern Libya – and Okba Ibn Nafaa, a group of al Qaeda-affiliated fighters operating in the Chaambi mountains along the Algerian border.
One Tunisian security source said many local Ansar al-Sharia militants were adopting the Islamic State banner. A top Ansar al Sharia commander, Ahmed Rouissi, was killed a week ago fighting under the badge of the Islamic State in Libya.
However, another Tunisian security source said preliminary indications showed the Bardo gunmen were more associated with Okba Ibn Nafaa, known more for its ties to fighters from Algeria and Mali than for links to the distant war in Syria and Iraq.
"There is no Islamic State structure in Tunisia, what you have are people attracted to their ideology, inspired by it," the source said.
Last year, an Al Qaeda splinter group in Algeria, Caliphate Soldiers, became one of the first in North Africa to declare allegiance to Islamic State. The group beheaded a French tourist, but since then the Algerian army, experienced after a decade of its own Islamist insurgency in the 1990s, has mostly hunted its members down, killing its leader and others.
Some North African militant commanders have stayed on the sidelines. Ansar al ShariaTunisia leader Abou Iyed, a veteran of fighting in Afghanistan, last year urged militants to put aside differences. He is now believed to be hiding out in southern Libya.
Algerian militant Mokhtar Belmokhtar, whose splinter group "Those who Sign in Blood" carried out the Amenas gas complex attack, has also left his position unclear on the rise of Islamic State. His group claimed responsibility for an attack earlier this month on a restaurant in the Malian capital Bamako, in which two Westerners and three Malians were shot to death.