Tunisia said two gunmen who killed 21 people at its national museum trained at a militant camp in Libya, as the country marked Independence Day in sombre mood on Friday.
The Islamic State group claimed Wednesday's attack on foreign tourists in Tunis, the deadliest since the 2011 revolution which sparked the Arab Spring regional uprisings.
The assailants "left the country illegally last December for Libya and they were able to train with weapons there," Secretary of State for Security Rafik Chelly said.
IS claimed the massacre at the National Bardo Museum and threatened more attacks.
Authorities say as many as 3,000 Tunisians have gone to Iraq, Syria and Libya to join IS and other jihadist groups, raising fears of returning battle-hardened militants plotting attacks.
Chelly named locations of several suspected training camps for Tunisians in violence-wracked Libya, including second city Benghazi and the jihadist stronghold of Derna.
President Beji Caid Essebsi's office said security forces arrested nine suspects -- "four people directly linked to the (terrorist) operation and five suspected of having ties to the cell".
Amid international outrage over the attack on Tunisia -- hailed as a rare Arab Spring success story -- Essebsi was defiant.
"The process of implementing a democratic system is underway, well anchored," he told French television. "We will never move backwards."
In a speech marking the anniversary of independence from France in 1956, he stressed that Tunisia's "first challenge is security" and urged "national unity".
Essebsi also met French Interior Minister Bernard Cazeneuve, who expressed solidarity with Tunisia, visited wounded French tourists and placed a wreath at the Bardo.
- Honeymooners hid in storeroom -
The dead tourists were four Italians, three Japanese, three French, two Spaniards, a Colombian, an Australian-Colombian, a British woman, a Belgian woman, three Poles and a Russian.
A Tunisian policeman killed in the attack was buried on Thursday.
Two Spaniards, a honeymooning couple, hid in a storeroom as the massacre took place, the husband told Spanish national television.
"We hid in a storeroom and stayed there, listening to everything that was happening and waiting for it to be over," Juan Carlos Sanchez said.
The attack was a massive blow to Tunisia's economy, which is heavily dependent on tourism.
At least two major cruise ship operators suspended Tunis calls after the attack.
Signup to our newsletter and follow us on Facebook and Twitter!
In Barcelona, hundreds disembarked from the MSC Splendida after their holiday was cut short. Twelve of its passengers were killed in Tunis.
Victoria Bronskaya, a tour guide from Belarus, recalled seeing two panic-stricken tourists gunned down as they tried to board the tour bus where she was cowering on the floor.
Their bodies blocked the way, perhaps saving her life because the "terrorist could not get on board".
Another passenger, Josefa Ramirez, said that after this experience "I don't want anything more to do with Arab countries".
Prime Minister Habib Essid named the two gunmen killed by security forces at the museum as Yassine Abidi and Hatem Khachnaoui, whose first name was later given as Jabeur by police in his home town.
Chelly said Abidi had been arrested before going to Libya, and that the pair had been "from sleeper cells".
Khachnaoui was described by a relative as a pious loner who never gave his parents a hard time.
- Gunman's relatives arrested -
He was said to have abruptly dropped out of high school months before graduation and gone to Libya, and there are suspicions he also visited Iraq.
Khachnaoui's father, two brothers and a sister have been arrested, the family and police said.
Essebsi said the gunmen also had explosives and praised the security forces for preventing further bloodshed.
Abdelfattah Mourou, deputy speaker of parliament, told AFP that guards supposed to be protecting parliament and the museum were having coffee as the assault happened.
"I found out there were only four policemen on security duty around the parliament (compound), two of whom were at the cafe. The third was having a snack and the fourth hadn't turned up," Mourou said.
A retired Colombian general whose wife and son were killed lamented the "irony" of losing them on holiday after spending his life "fighting terrorism" at home.
Tunisia has seen an upsurge in Islamist extremism since the 2011 revolution that ousted dictator Zine El Abidine Ben Ali and sparked the Arab Spring.
EU president Donald Tusk and foreign affairs chief Federica Mogherini will visit Tunis on March 31 to boost security cooperation, Mogherini said Friday.
Tunisia has taken pride in forming a democratic government and achieving stability since the Arab Spring -- in marked contrast to countries such as Egypt and Libya.
But dozens of police and military personnel have been killed in attacks blamed on Islamist militants.