Two gunmen who killed 21 people at a museum in Tunis trained in neighbouring Libya before the attack, Tunisian security officials have said.

Rafik Chelli, the Interior Ministry's senior security official, said the attackers 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 details about where or with which group they trained.

Wednesday's attack at the National Bardo Museum killed 21 people, 17 of them cruise ship tourists, including British mother-of-two Sally Adey.

The two gunmen were killed in a firefight with security forces.

The Islamic State group based in Iraq and Syria has claimed the attack. Several well-armed groups in Libya have pledged allegiance to IS.

Police in Tunisia have arrested five people described as directly tied to the two gunmen. Four others said to be supporters of the cell were also arrested in central Tunisia, not far from where a group claiming allegiance to al Qaida's North African branch has been active.

IS 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".

Several well-armed groups in neighbouring and chaotic Libya had already pledged their allegiance to IS.

But the attack of such magnitude in Tunisia - the only country to emerge from the Arab Spring uprisings with a functioning democracy - raised concern about the spread of extremism to the rest of North Africa.

Analysts warned against seeing every such attack as evidence of a well-organised, centrally controlled entity spanning the Middle East, saying instead that small groups could merely be taking inspiration from the high-profile militant group.

Tunisian health minister Samar Samoud said the latest tally of victims also includes four Italians, three Japanese, three French, two Spanish, two Colombians and one each from Poland and Belgium.

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 IS.

Tunisian authorities have estimated that of the 3,000 young people who left the country to fight with radical groups, about 500 have returned.

Prime minister Habib Essid yesterday announced new security measures around the country, including a crackdown on websites seen as promoting terrorism.

The deaths of so many foreigners will damage Tunisia's tourism industry, which draws thousands to its Mediterranean beaches, desert oases and ancient Roman ruins. The industry had just started to recover after years of decline. The two cruise ship lines who had passengers killed in Tunis on Wednesday announced they were dropping Tunis from their itineraries for now.

Sign up to our free newsletters

Get the best updates straight to your inbox:
Please select at least one mailing list.

You can unsubscribe at any time by clicking the link in the footer of our emails. We use Mailchimp as our marketing platform. By subscribing, you acknowledge that your information will be transferred to Mailchimp for processing.