Somali security heads fired over attack

A car bomb that exploded in Mogadishu during an Islamist attack on the weekend has caused carnage. (AAP)

The Somali government has sacked the nation's police commander and the head of its intelligence agency after another Islamist attack in the capital.

The Somali government has sacked two top security officials after yet another Islamist attack on a hotel in Mogadishu, which killed 29 people in a siege that lasted nearly 12 hours.

On Sunday, the government sacked the country's police commander, Abdihakin Dahir Saiid, and the director-general of the National Intelligence Security Agency, Abdullahi Mohamed Ali, the prime minister's office announced.

The attack proved once again that insurgents can carry out deadly assaults in the heart of the Somali capital.

Twin bombings in Mogadishu two weeks ago killed more than 350 people, the worst such attacks in the country's history. More than 50 people are still missing.

Islamist militants al Shabaab claimed responsibility for the weekend attack, which took place ahead of a planned meeting to try to defuse tensions between the federal government and regional states. Government officials had begun to meet at the hotel to discuss strategy.

"So far I am sure 29 people died - the death toll may rise," Abdullahi Nur, a police officer, told Reuters.

At least 12 of the dead were police officers, Nur said. A woman was beheaded while her "three children were shot dead", he said.

Three militants were captured alive and two others blew themselves up after they were shot, police said. Some militants may have disguised themselves and escaped with the residents who were rescued from the hotel, one police officer said.

The attack began around at 5pm on Saturday when a car bomb rammed the gates of Nasahablod Two hotel, which is close to the presidential palace, and destroyed the hotel's defences. Then gunmen stormed the building.

The explosion destroyed the front of the three-storey hotel and damaged the hotel next door.

The attack presents a further challenge to the new government of President Mohamed Abdullahi Mohamed, whose defence minister and chief of army staff resigned this month.