Somalia's security forces ended a deadly siege of a beachfront restaurant in the capital, with more than 20 people killed in the attack, a police official said Friday.

The security forces took control of the restaurant just before dawn, said Capt. 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.

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.

Hussein 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.

Witnesses said that gunmen shouted "Allahu akbar," the Arabic phrase for "God is great," and entered the restaurant from the direction of the beach as clients, sitting behind razor wire, watched the seashore.

"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.

Somalis walk past the wreckage of vehicles outside the beachfront restaurant on Friday following an overnight attack in Mogadishu. (Farah Abdi Warsameh/Associated Press)

Islamic extremist group al-Shabaab claimed responsibility for the attack, in a broadcast on its online radio late Thursday.

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. African Union troops, government officials and foreigners are frequently targeted.