The president of Tunisia declared a state of emergency yesterday to give his government more powers following the terror attack in which 38 tourists were killed.

The emergency law temporarily gives the government more executive flexibility, hands the army and police more authority, and restricts certain rights such as the right to public assembly.

The move by President Beji Caid Essebsi comes after two of the worst terrorist attacks in Tunisia's modern history taking place in the space of less than four months.

The attack on the Sousse beach resort followed a gun attack on the Bardo museum in Tunis in March, in which 21 tourists and a policeman were killed.

Tunisian officials say all three gunmen in those two attacks had been trained at the same time, over the border in jihadist camps in Libya, where a conflict between two rival governments has allowed Islamist militant groups to gain ground.

Militants from Islamic State - now being referred to as Daesh by the Sunday Herald - have claimed responsibility for the massacre at the hotel in Sousse, in which gunman Seifeddine Rezgui shot tourists as they sat at the beach and by the pool of the Imperial Marhaba hotel.

Tunisian authorities believe militant group Ansar al-Sharia is directly responsible for orchestrating the attack against the Sousse hotel, which prompted thousands of tourists to leave Tunisia and is expected to cause $500 million - around £320 million - in losses to the sector.

Ansar al-Sharia was blamed for the storming of the US embassy in Tunis in 2012 and the assassination of two Tunisian opposition leaders. But it has mostly disbanded and its hardline militants left to fight overseas in Iraq, Syria and Libya.

"For the moment, this was Ansar al-Sharia who were behind this," said the Tunisian security source.

Daesh also claimed the Bardo attack, but the government said it was linked to the local al-Qaeda linked Okba Ibn Nafaa brigade.

However experts say that, like in other regions, younger fighters and recruits might be breaking away from these organisations inspired more by the propaganda of Daesh.

In reaction to militant recruiters, the Tunisian government has also said it will close 80 mosques that are operating illegally or preaching extremist messages.

Tunisia last had a state of emergency during the 2011 uprising against former president Zine el-Abidine Ben Ali, who was eventually forced to flee to Saudi Arabia following a month of protests against his rule.