European Union foreign policy chief Federica Mogherini has blamed Islamic State for an attack on tourists in a museum in Tunisia that killed 19 people, including 17 foreign tourists.

"With the attack that has struck Tunis today, the Daesh terrorist organisation is once again targeting the countries and peoples of the Mediterranean region," she said in a statement, using the Arabic acronym for Islamic State.

"This strengthens our determination to cooperate more closely with our partners to confront the terrorist threat," she said. "The EU is determined to mobilise all the tools it has to fully support Tunisia in the fight against terrorism and reforming the security sector.

Earlier, Tunisian security forces said they had freed all the hostages held in the museum. The victims include Italians, Spaniards and Poles.

Two militants were killed in clashes after gunmen assaulted the Bardo museum, a venue in central Tunis on the parliament grounds which is a popular site for visiting foreigners.

The attack on such a high profile target was a huge blow for Tunisia, which relies heavily on European tourism and has so far avoided major militant violence since its 2011 uprising to oust autocrat Zine El-Abidine Ben Ali.

Today's assault was the worst involving tourists since an al Qaeda suicide bombing on a synagogue killed 21 people on the tourist island of Djerba in 2002.  

Tunisia uprising inspired "Arab Spring" revolts in neighbouring Libya, Egypt, Syria and Yemen. But its adoption of a new constitution and staging of largely peaceful elections has won widespread praise and stood in stark contrast to the chaos that has plagued those countries.

Several militant groups have emerged in Tunisia since the uprising, including Ansar al Sharia which is listed as a terrorist organisation by the United States.

Authorities estimate 3,000 Tunisians have also joined militant groups in Iraq and Syria and some have returned home, increasing government fears of an attack on Tunisian soil.

Islamic State affiliates in Libya are gaining a foothold as two rival governments there battle for control. A senior Tunisian militant was killed while fighting for Islamic State in the Libyan city of Sirte over the past week, authorities said.

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.