At least 20 people have died in a terrorist attack in Somalia. A siege at a beachfront restaurant in the capital Mogadishu ended this morning after more than eight hours.

Islamic extremist group al-Shabab has claimed responsibility for the attack.

The security forces took control of the restaurant just before dawn, said Captain Mohamed Hussein, speaking from the scene of the attack in Mogadishu.

It was not clear whether Hussein's report of more than 20 killed included the assailants. Members of al-Shabaab claimed responsibility for the attack in a broadcast on its online radio late on Thursday.

"I was intending to go out but suddenly we heard a heavy explosion followed by gunfire. ... I saw a militant fighter shooting indiscriminately on everybody. Then I locked myself inside a room until we were evacuated peacefully by the security forces," said Abdulkadir Mohamed Somow, who had been trapped inside the restaurant.

Blasts and bursts of gunfire could be heard as Somali special forces went from room to room pursuing the al-Shabaab gunmen who were holed up inside the restaurant.

In pictures: Mogadishu attack Show all 10 1 /10 In pictures: Mogadishu attack In pictures: Mogadishu attack People carry an injured man after Somali security forces took control over of the restaurant and ended the siege where gunmen exploded car bombs and opened fire on people In pictures: Mogadishu attack A soldier patrols on Lido beach following an attack at beachside restaurant Beach View Cafe, in Somalia's capital Mogadishu Reuters In pictures: Mogadishu attack In pictures: Mogadishu attack People gather to assess the damage at Lido beach following an attack at beachside restaurant Beach View Cafe, in Somalia's capital Mogadishu Reuters In pictures: Mogadishu attack A policeman and residents walk past the wreckage of cars destroyed in a car bomb attack outside beachside restaurant Beach View Cafe on Lido beach, in Somalia's capital Mogadishu Reuters In pictures: Mogadishu attack Relatives carry away a dead body from the beach, following an overnight attack on a beachfront restaurant in Mogadishu AP In pictures: Mogadishu attack A Somali soldier walks past wrecked cars in front of the Lido seafood restaurant following an overnight attack on the beachfront restaurant in Mogadishu Getty Images In pictures: Mogadishu attack A general view through a broken glass shows government forces patrolling on Lido beach following an attack at beachside restaurant Beach View Cafe in Somalia's capital Mogadishu Reuters In pictures: Mogadishu attack In pictures: Mogadishu attack Ambulance workers stand by near the Lido beach where gunmen exploded a car bomb and opened fire at a restaurant in Mogadishu EPA

Hussein, the police official, said the security forces rescued many people who had been trapped inside the restaurant's hall, where a party was taking place when the attack started on Thursday.

An eye witness told The BBC that a wedding ceremony was taking place in the hall of the restaurant when the attack happened.

Witnesses said that gunmen entered the restaurant from the direction of the beach. They shouted "Allahu akbar," the Arabic phrase for "God is great," as they attacked.

"They randomly fired at people sitting near the beach before entering the restaurant,”" said witness Ahmed Nur, who was strolling along the shoreline when the attack happened.

Al-Shabaab attacked Kenyan peacekeepers in southwestern Somalia last week.

The al-Qaeda-linked group said it had killed about 100 Kenyans and seized weapons and military vehicles.

The Kenyan government has given no death toll, but said there were some fatalities.

Despite being pushed out of Somalia's major cities and towns, al-Shabaab continues to launch deadly guerrilla attacks across the Horn of Africa country.