The gunman who killed 38 tourists, mostly Britons, in a Tunisian beach attack was trained in neighbouring Libya at the same time as the attackers who targeted the Bardo museum in March, an official has said.

Security chief Rafik Chelli said gunman Seifeddine Rezgui, a Master's student in electrical engineering at Kairouan University, sneaked into Libya in January and trained near the western town of Sabratha.

The two attackers who carried out the Bardo museum attack in Tunis in March that killed 22 people were there at the same time.

The attack near the resort town of Sousse was the worst in Tunisia's history and has devastated the country's vital tourism sector.

Sabratha, also the site of famed Roman ruins, is known to contain training camps for jihadis.

The March led to repeated criticisms of the Tunisian government for not doing more to prevent another attack on visiting foreigners.

Earlier, the Tunisian president revealed that the attack took place just days before the country planned to implement heightened security measures for the Muslim fasting month of Ramadan.

However, the plans, which were scheduled to be put into place on July 1, had not anticipated an assault on tourist beaches, Beji Caid Essebsi added.

The attack in Sousse is expected to cripple the vital tourism sector, with the Tunisian tourism minister predicting half billion dollars in losses for 2015.

In an interview with Europe 1 radio, president Essebsi said an investigation into security failures is under way, and there will now be armed tourist police on the beaches. Army reservists have also been called up.

Mr Essebsi said: "It is not a perfect system - it is true we were surprised by this affair.

"They took measures for the month of Ramadan but never did they think the attack would be on the beaches against tourists, and the system of protection was set to start July 1."

Mr Essebsi, 88, is a veteran of Tunisia's pre-revolutionary regime and was elected last autumn on a platform of restoring security and dignity to the state.

The country's vital tourism sector suffered a staggering blow when 24-year-old Rezgui used an assault rifle to kill 38 tourists, mostly Britons. The rampage continued for around half an hour before he was finally shot dead by police. It is Tunisia's worst terror attack.

Since the massacre, authorities have shut 80 unregulated mosques believed to be preaching radical doctrine, and have considered closing organisations and political parties promoting ideas counter to the constitution.

"What is threatened is our way of life and society," Mr Essebsi said, praising Tunisia as one of the only democracies in the region.

"It is not easy being the exception; we should be the model, but it is a model not yet accepted by the others."

He added that Tunisia needs more assistance in securing its frontiers, especially with Libya, home to supporters of the radical Islamic State group which claimed responsibility for the attack.

Tourism minister Samia Elloumi outlined a series of measures to cushion the industry from an expected loss of just over half a billion dollars following the attack.

She said debts and taxes for tourist companies would be rescheduled, new loans guaranteed by the state would be offered and transport taxes for non-resident Tunisians would be cut.

Most important for foreigners, the $15 departure tax will be scrapped and visa requirements will be been lifted for visitors from China, India, Iran and Jordan.

The current tourism promotion campaign will also be pulled.

Ms Elloumi said: "It would be indecent and not send a positive message to put out such a campaign while the bodies of the victims are still there and people remain in shock."

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.