SOUSSE, Tunisia (Reuters) - A gunman disguised as a tourist opened fire at a Tunisian hotel on Friday with a rifle he had hidden in an umbrella, killing 39 people including Britons, Germans and Belgians as they lounged at the beach in an attack claimed by Islamic State.

Terrified tourists ran for cover after the gunfire and an explosion erupted at the Imperial Marhaba in Sousse, 140 km (90 miles) south of the capital Tunis, before police shot the gunman dead, witnesses and security officials said.

The bodies of several tourists lay crumbled where they fell in the sand, covered with yellow towels and blankets among the plastic white sunbeds. Blood smeared stone steps leading from the hotel main area.

“This was always a safe place but today was horror,” said an Irish tourist who gave only his first name, Anthony. “He started on the beach and went to the lobby, killing in cold blood.”

The attack took place during the holy Muslim month of Ramadan, on a day in which a decapitated body daubed with Arabic writing was found in France, a suicide bomber killed two dozen people at a mosque in Kuwait and at least 145 civilians were reported killed by Islamic State militants in northern Syria.

In a statement on social media, Islamic State claimed responsibility for the Tunisian attack. It had urged its followers to step up assaults during Ramadan.

Twitter accounts that support Islamic State released three photos they said showed the gunman. A man is seen from behind walking down a street and holding an assault rifle, though his identity and the location are unclear.

“Our brother, the soldier of the Caliphate, Abu Yihya al-Kairouni, reached his target the Imperial hotel despite the security measures,” the statement said. It said he had attacked a “bordel” and killed 40 “infidels’.

After pulling out a weapon hidden inside an umbrella, the assailant strolled through the hotel grounds, opening fire left and right at the pool and beach, reloading his weapon several times and tossing an explosive, witnesses said.

A security source said another bomb was found on his body, which lay with a Kalashnikov assault rifle where he was shot.

Rafik Chelli, a senior interior ministry official, said the gunman killed was unknown to authorities and not on any watchlist of potential jihadists. A security source named him as Saifeddine Rezgui, a 23-year-old electrical engineering student.

Local radio said police captured a second gunman, but officials did not immediately confirm the arrest or his role in the attack.

“It was just one attacker,” said a hotel worker at the site. “He was a young guy dressed in shorts like he was a tourist himself.”

“RUN, RUN, RUN!”

It was the worst attack in Tunisia’s modern history and the second major massacre this year following the Islamist militant assault on Tunis Bardo museum when gunmen killed 21 foreign visitors.

A health ministry statement said British, German and Belgian nationals were among the 39 dead. The health minister told French radio 36 others were wounded in the shooting.

At least five British citizens were among the dead, Britain’s Foreign Minister Philip Hammond said. Ireland’s foreign ministry said at least one Irish citizen was killed.

Slideshow ( 8 images )

Tunisia, which has been hailed as a model of democratic transition since its 2011 ‘Arab Spring’ uprising, is one of the most secular countries in the Arab world. Its beach resorts and nightclubs on the Mediterranean are popular with foreigners.

Islamist jihadists have attacked North African tourist sites before, seeing them as legitimate targets because of their open Western lifestyles and tolerance of alcohol.

Irishwoman Elizabeth O’Brien, who was staying at a neighboring hotel with her two sons, said there was panic on the beach when gunfire erupted.

“I honestly thought it was fireworks and then when I saw people running... I thought, my God, it is shooting,” she told Irish radio station RTE. “The waiters and the security on the beach started to say ‘Run, run, run!’”

Slideshow ( 8 images )

CATASTROPHE

Islamic State made some claim to the Bardo museum attack, but authorities blamed possible splinter fighters from the Okba Ibn Nafaa, a brigade of al Qaeda-affiliated fighters, operating in the Chaambi mountains along the Algerian border.

In Sousse, many tourists were already packing their suitcases into busses and checking out of hotels to leave after the attack.

German tour operator TUI said on Friday it was organizing flights for tourists wishing to return from Tunisia and said those who booked Tunisian holidays for this summer could rebook or cancel the trips free of charge.

Sousse, alongside nearby Hammamet and the island of Djerba, is the heartland of Tunisia’s most popular beach resorts, drawing visitors from Europe and neighboring North African countries like Algeria.

Six million tourists, mostly Europeans, visited Tunisia’s beaches, desert treks and medina souks last year, providing seven percent of its gross domestic product, most of its foreign currency revenues and more jobs than anything but farming.

“This is a catastrophe for the economy,” Tourism Minister Salma Loumi said. “Our losses will be great, but the loss of human life was even greater.”

Since its 2011 uprising to oust autocrat Zine el-Abidine Ben Ali, Tunisia has been praised for its peaceful democratic transition bringing free elections and a new constitution seen as a model for the region.

But the country has also struggled with the rise of Islamist movements as ultra-conservative preachers took advantage of the upheaval and young democracy to take over mosques and spread their hardline message.

Several thousand Tunisian jihadists have left the country to fight in Syria, Iraq and neighboring Libya, where some have set up jihadist training camps and promised to return to attack their homeland.