The two extremist gunmen who killed 21 people at a museum in Tunis trained in neighbouring Libya before carrying out the deadly attack, a top Tunisian security official said.
The Islamic State group based in Iraq and Syria has claimed responsibility for the Bardo attack. Several well-armed groups in Libya, which borders Tunisia, have pledged their allegiance to Islamic State.
- Who are Islamic State? Get caught up with The Globe’s primer
- A visual guide to the Middle East’s shifting relationships
Wednesday's attack at the National Bardo Museum killed 21 people – 17 of them cruise ship tourists – before the two gunmen were killed in a firefight with security forces. The attack of such magnitude in Tunisia – the only country to emerge from the 2011 Arab Spring uprisings with a functioning democracy – raised concerns about the spread of extremism to the rest of North Africa.
Rafik Chelli, the Interior Ministry's top security official, said the attackers had slipped out of Tunisia in December and received weapons training in Libya before returning home. He told the El Hiwar El Tounsi TV channel that authorities did not have further details about where or with which group they had trained.
Police in Tunisia have arrested five people described as directly tied to the two gunmen as well as four others in central Tunisia said to be supporters of their cell.
Tunisians on Thursday stepped around trails of blood and broken glass outside the museum to rally in solidarity with the 21 victims and with the country's fledgling democracy. Marchers carried signs saying, "No to terrorism" and "Tunisia is bloodied but still standing."
Two of the cruise ships that had passengers killed or wounded in the Tunis attack sailed into Spanish ports on Friday, with disembarking passengers telling reporters chilling tales of how they just missed being victims.
In Palma, Spanish cruise ship passenger Catalina Llinas told reporters she and her husband luckily chose a day trip Wednesday to the Roman ruins of Carthage near Tunis instead of the museum excursion. The couple's tour bus, she said, passed by the Bardo museum just 10 minutes before the attacks.
"It could have been us," she said.
In claiming responsibility for the attack, the Islamic State group issued a statement and audio on jihadi websites applauding the dead gunmen as "knights" for their "blessed invasion of one of the dens of infidels and vice in Muslim Tunisia."
Analysts cautioned against seeing every such attack as evidence of a well-organized, centrally controlled entity spanning the Middle East, saying instead that small groups could merely be taking inspiration from the high-profile militant group.
"I think [Islamic State] is probably taking credit for something it may not have played a role in," said Geoff Porter, a security analyst for North Africa.
Confronted with a poor economy, young Tunisians have disproportionately gone abroad to fight with extremist groups in Libya, Syria and Iraq, including some affiliated with Islamic State. Tunisian authorities have estimated that of the 3,000 young people who left the country to fight with radical groups, about 500 have returned.
The deaths of so many foreigners will damage Tunisia's tourism industry, which draws thousands of foreigners to its Mediterranean beaches, desert oases and ancient Roman ruins. The industry had just started to recover after years of decline.
Culture Minister Latifa Lakhdar gave a defiant news conference Thursday at the museum, where blood still stained the floor amid the Roman-era mosaics.
"They are targeting knowledge. They are targeting science. They are targeting reason. They are targeting history. They are targeting memory, because all these things mean nothing in their eyes," she told reporters.