At least 27 people, including foreign tourists, were killed when at least one gunman opened fire on a Tunisian beachside hotel in the popular resort of Sousse on Friday, an interior ministry spokesman said.

Police were still clearing the area around the Imperial Marhaba hotel and the body of one gunman lay at the scene with a Kalashnikov assault rifle after he was shot in an exchange of gunfire, a security source at the scene said.

It was the second major attack in the North African country this year, and took place during the holy Muslim month of Ramadan.

"One attacker opened fire with a Kalashnikov on tourists and Tunisians on the beach of the hotel," said a hotel worker at the site. "It was just one attacker. He was a young guy dressed in shorts like he was a tourist himself."

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 Mediterraneanare popular with European visitors.

No one immediately claimed the attack. But Islamist jihadists have attacked North African tourist sites before, seeing them as legitimate targets because of their open Western lifestyles and tolerance of alcohol.

Six other people were wounded, the ministry spokesman said.

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!'"

Sousse is one of Tunisia's most popular beach resorts, drawing visitors from Europe and neighboring North African countries. Tourism is also a major source of income for the government.

Tunisia has been on high alert since March, when Islamist militant gunmen attacked the Bardo museum inTunis, killing a group of foreign tourists in one of the worst attacks in a decade in the North African country.

Since its 2011 uprising to oust autocrat Zine el-Abidine Ben Ali, Tunisia has been praised for its peaceful democratic transition. But it has also seen the rise of hardline conservative Islamist movements.

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