The Islamic State group on Saturday claimed responsibility for a massacre in a Tunisian seaside resort that killed nearly 40 people, most of them British tourists, in the worst attack in the country's recent history.
Dozens more were wounded when a man pulled a gun from inside a beach umbrella and opened fire on crowds of tourists at the five-star Riu Imperial Marhaba Hotel in the popular Mediterranean resort of Port el Kantaoui.
Tunisian Prime Minister Habib Essid said 38 people had been killed, revising down an earlier toll of 39 given by the health ministry. An official there told AFP the original figure had included the dead gunman.
Most of those killed were from Britain -- implying this could be the biggest loss of British life in a militant attack since the July 2005 bombings in London when 52 died -- while Germans, Belgians, French were also among the dead, the premier said.
Britain's Foreign Secretary Philip Hammond said earlier five Britons had been killed and he expected the toll to rise, while his Irish counterpart confirmed an Irish woman was among the dead.
The attack, the second against tourists in Tunisia this year, comes on the same day that 27 people were killed at a Shiite mosque in Kuwait and a suspected Islamist attacked a factory in France.
IS claimed both the bombing and the attack in Tunisia, which came at the start of the holy Muslim month of Ramadan and just days before the first anniversary of the group declaring its territory in Iraq and Syria a "caliphate".
IS said the gunman, who they identified as Abu Yahya al-Qayrawani, was a "solider of the caliphate" who had targeted enemies of the jihadist group and "dens (of...) fornication, vice and apostasy".
Most of those killed were "subjects of states that make up the crusader alliance fighting the state of the caliphate", the group said in a statement released on Twitter, referring to the group of countries that have been bombarding its positions in the Middle East.
The attack, along with the killings in France and Kuwait, sparked a chorus of international condemnation with the White House vowing to "fight the scourge of terrorism" and UN Secretary-General Ban Ki-moon saying those responsible for the "appalling" attacks "must be swiftly brought to justice".
Tunisian Secretary of State for Security Rafik Chelly told Mosaique FM the gunman was a Tunisian student previously unknown to the authorities.
"He entered by the beach, dressed like someone who was going to swim, and he had a beach umbrella with his gun in it. Then when he came to the beach he used his weapon," Chelly said.
Witnesses described scenes of panic after the shooting at the hotel on the outskirts of Sousse, about 140 kilometres (90 miles) south of the capital Tunis.
"All I saw was a gun and an umbrella being dropped," British tourist Ellie Makin told ITV television.
"Then he started firing to the right-hand side of us. If he had fired to the left I don't know what would have happened, but we were very lucky."
The shooting was the worst in modern-day Tunisia and followed a March attack claimed by IS on Tunis's Bardo National Museum that killed 21 foreign tourists and a policeman.
British tourist Gary Pine told Britain's Sky News television Friday's attack happened when the beach was packed. He counted 20-30 shots.
"My son was in the sea at the time and of course my wife and myself were shouting for him to get out the sea quick and as we ran up the beach he said: 'I just saw someone get shot'."
Briton Olivia Leathley, 24, heard "loud bangs" and when she went to the lobby to find out what was happening, she saw a woman whose husband had "been shot in the stomach in front of her".
"All she said was that he'd been shot and that he was there bleeding on the beach and he was just saying, 'I love you, I love you', and then his eyes rolled back into his head."
Another woman described how her fiance was shot three times while trying to protect her and was in intensive care in hospital.
"I owe him my life because he threw himself in front of me when the shooting started," 26-year-old holidaymaker Saera Wilson told the BBC.
By the early hours of Saturday morning, hundreds of tourists were arriving at Enfidha airport in a mad scramble to leave the country, according to an AFP journalist on the scene.
Essid on Saturday announced new anti-terrorism measures, including the deployment of reserve troops to reinforce security at "sensitive sites... and places that could be targets of terrorist attacks".
The "exceptional plan to better secure tourist and archaeological sites" will include "deploying armed tourist security officers all along the coast and inside hotels from 1 July," he added.
Tunisian President Beji Caid Essebsi told AFP that his country cannot stand up to the jihadist threat alone, and urged a unified global strategy.
In Cairo, leading Sunni Muslim institution Al-Azhar called the "heinous" shooting a "violation of all religious and humanitarian norms".
Tunisia, birthplace of the Arab Spring, has seen a surge in radical Islam since veteran president Zine El Abidine Ben Ali was ousted in the 2011 revolution.
Dozens of members of the security forces have been killed in jihadist attacks since then.
In October 2013, a suicide bomber blew himself up in a botched attack on a Sousse beach while security forces foiled another planned attack nearby.
Even before the latest attack, Tunisia's tourism industry had been bracing for a heavy blow from the Bardo shooting, but was determined to attract tourists with new security measures and advertising.
Tourism accounts for seven percent of Tunisia's GDP and almost 400,000 direct and indirect jobs.