Instability in Libya and fighters trained in Syria and Iraq returning to Tunisia might be behind the attack that killed 17 foreign tourists and two Tunisians in national museum in Bardo

Gunmen wearing military uniforms stormed Tunisia's national museum, killing 17 foreign tourists and two Tunisians on Wednesday in one of the worst militant attacks in a country that had largely escaped the region's "Arab Spring" turmoil.

Visitors from Italy, Germany, Poland and Spain were among the dead in the noon assault on Bardo museum inside the heavily guarded parliament compound in central Tunis, Prime Minister Habib Essid said.

"They just started opening fire on the tourists as they were getting out of the buses ... I couldn't see anything except blood and the dead," the driver of a tourist coach told journalists at the scene.

Scores of visitors fled into the museum and the militants took hostages inside, government officials said. Security forces entered the building, a former palace, around two hours later, killed two militants and freed the captives, a government spokesman said. A police officer died in the operation.

The attack on such a high-profile target is a blow for the small North African country that relies heavily on European tourism and has mostly avoided major militant violence since its 2011 uprising to oust autocrat Zine El-Abidine Ben Ali.

Authorities did not immediately identify the gunmen. But several Islamist militant groups have emerged in Tunisia since the uprising, and authorities estimate about 3,000 Tunisians have also joined fighters in Iraq and Syria -- raising fears they could return and mount attacks at home.