The attack at Tunsia's famed Bardo museum on Wednesday exposed an extremist threat that reaches to the heart of the country's capital.
It was an attack in a highly symbolic place, next to the parliament, and against a key industry - tourism. The presidency said Tunisia was facing "exceptional circumstances".
But the attack was also an escalation of militant violence in Tunisia that had long been feared. As such, it was met with statements of resilience and determination that the country would not be thrown off course.
"It was a huge shock, Tunisia has never been like that - we're an open country," said Aida Ayari, a 37-year-old attending an anti-terrorism rally at the museum a day after the attack. "But we're not going to remain shocked."
As she and others pointed out, such attacks can - and have - happened elsewhere.
'Installed in our city'
But Tunisia's political fortunes - it was the only country in the region to complete a democratic transition - and its secularist-led government may have made it more of a target for extremists.
And two problems make Tunisia especially vulnerable.
In Libya, its neighbour to the east, the state has been collapsing and huge quantities of arms have found their way out of the country.
In neglected border regions, Islamist militants have easily acquired those weapons after developing ties with criminal groups involved in arms and drugs trafficking.
Meanwhile, Islamist campaigns in Iraq and Syria have attracted disproportionately high numbers of Tunisian fighters, hundreds of whom have returned home.
Islamic State, which according to an audio message posted on Thursday said it had carried out the Tunis attack, has a growing presence in Libya - a country that was already serving as a training ground for fighters travelling on to the Middle East.
Some 1,500 Tunisians attached to the outlawed Islamist group Ansar al-Sharia and aligned with IS are thought to be training there, preparing to return to Tunisia and carve out a presence, said Badra Gaaloul, who heads a security think-tank in Tunis.
Counter-terrorism policy has failed to keep up as militants have changed their strategy, she said.
The militants have shown "that they're installed in our city and our neighbourhoods and can carry out attacks in broad daylight in a place where there's plenty of security".
Security and intelligence officials "realise how serious it is - that there's a great risk to Tunisia, but they lack co-ordination and experience", she added.
The Bardo museum is opposite a barracks and round the corner from the heavily guarded parliament building.
When police officers let demonstrators approach the museum little more than 24 hours after the attack, bloodstains still marked the ground and some marble paving at the entrance lay broken where an armoured vehicle had tried to back up to the building's glass doors.
A plain-clothes policeman said security forces had arrived quickly, but they had struggled to contain gunmen firing indiscriminately.
Protesters chanted about their dissatisfaction with both the current, secularist-led, government, and the previous, Islamist-led administration, blaming them for letting the attack happen.
Some deficiencies may be tackled by new anti-terrorism legislation that was ready for discussion at the very moment the attack began.
The draft law could assign police tasks to the military in urban areas, and give the security forces greater leeway to crack down on radicalisation.
Gaigi Afif, one of a group of black-robed lawyers who turned out to Thursday's anti-terrorism rally, said he hoped the law would give the authorities more scope to tap phones and make swift arrests.
"I don't think that the situation in Tunisia will automatically deteriorate, but we have to be much more vigilant," he said.
Tunisia remains polarised between staunch secularists - who tend to be drawn from the east coast, Francophone elite - and poorer, more religiously conservative populations in the south and the interior. The politics that result have hampered effective policy around Islamism.
But the international community could also help with counter-terrorism advice, training or technological support to monitor vast desert spaces on the Libyan border, Michael Bechir Ayari, an analyst for International Crisis Group, wrote in a briefing paper.
"The positive side of this tragedy is that it has awakened a sense of solidarity with Tunisia in its struggle to ensure that it avoids anything like the fate of its Libyan neighbour," he said.
"And if the world values what Tunisia has achieved since 2011, it needs to respond."