Tunisia's prime minister has called for all citizens to work together to defeat terrorism as thousands of tourists prepared to leave the North African country in the wake of its worst terrorist attack.

Tourists crowded into the airport at Hammamet near the coastal city of Sousse where a young man dressed in shorts pulled an assault rifle out of his beach umbrella and killed 39 people, mostly tourists.

"The fight against terrorism is a national responsibility," said a visibly exhausted Habib Essid at a press conference in Tunis. "We are at war against terrorism which represents a serious danger to national unity during this delicate period that the nation is going through."

He announced a string of tough measures to fight extremism, including examining the funding of organisations suspected of promoting radicalism, closing some 80 mosques outside government control and declaring certain mountainous zones military areas.

He identified the gunman, who was killed by police after the attack, as Seifeddine Rezgui, a young student at Kairouan University. A tweet from the Islamic State group claimed responsibility for the attack and gave his jihadi pseudonym of Abu Yahya al-Qayrawani, according to the SITE intelligence group.

At the Imperial Marhaba Hotel where the attack took place, buses were carrying away tourists. While the hotel was not actually closing down, the tour operators had urged everyone to leave, the director said.

"We may have zero clients today but we will keep our staff," said Mohammed Becheur, adding the 370-room hotel had been at 75% occupancy before the attack.

Tourism is a key part of Tunisia's economy and had already fallen about 25% after a terrorist attack on the national museum in the capital Tunis that killed 22 people in March.

"It's really sad but what can you do, for everyone, for the tourists, for the people who died, for their families," said Belgian tourist Clause Besser, as he recovered in hospital from a gunshot wound he received fleeing from the attacker. "For me, somehow, with a bullet in the leg, it's not a catastrophe. For those who died or were injured for life, it's something else."

British travel companies Thomson and First Choice said they are flying back thousands of tourists from Tunisia and are cancelling all flights to the country in the coming week.

Tourist flights from Ireland to Tunisia have continued in the wake of the attack but travel agents are offering full refunds for those cancelling.

Slovakia has sent a plane to evacuate 150 of its citizens who are currently in Tunisia, according to the Foreign Ministry and Scandinavian tour operators have stopped all flights to the North African country for the rest of the season.

The Tunisian Ministry of Health has confirmed the nationalities of 10 of the 39 victims of the attack, including eight Britons, a Belgian and a German. The government of Ireland said an Irish nurse was also among those who were killed.

Relatives and family friends say Lorna Carty was shot as she sunbathed. She and her husband, Declan, had received the holiday as a present to help Declan Carty relax following his recent heart surgery.

A spokesman for the Health Ministry said a total of 39 people were wounded in the attack, including 21 who have already left hospital.

Chokri Nafi said that 18 are under observation, including two who are in a critical condition.

He said the nationalities of the injured include seven Tunisians, 25 Britons, three Belgians, one German, one Ukrainian, one Russian and one who has not yet been identified.

The director of the Enfidha-Hammamet airport in Tunisia said it has set up special procedures to accommodate the flood of passengers seeking to leave the country.

Mohamed Walid Ben Ghachem said about 15 extra flights have been scheduled at the airport since yesterday, with nine already leaving, carrying 1,400 passengers. He noted that four of the planes left empty, indicating that least 1,000 people had decided to stay on after the attack.

British tourist Matthew Price said he was cutting his week-long holiday short by three days and even though it was his third visit to Tunisia, he expected it to be his last.

"It's the first time I've ever been on holiday and feared for my life. So obviously you can't come back somewhere it's not safe," he said.