Five Islamic extremists have attacked a hotel in the Somali capital, Mogadishu, killing at least six people and injuring 10, before all the assailants were killed.

Security forces ended the siege by the al-Shabab attackers at the Sahafi Hotel by midday on Sunday, said police commander Ali Ahmed.

"It's over now, we have killed all the attackers," said Mr Ahmed. "They came under cover of darkness and attacked the hotel while some of the guards were sleeping."

The attack started at daybreak when a suicide bomber detonated a vehicle laden with explosives at the gate of the Sahafi Hotel and then men armed with AK-47 rifles, propelled grenades and suicide vests invaded the hotel.

Some of them went into rooms to kill residents while others went to the rooftop to fight government soldiers who came to fight the attackers, said Captain Mohamed Hussein, a senior Somali police officer.

A second explosion came from a car bomb outside the hotel, said witnesses. Among those killed was the hotel's owner and a former general.

"Had it not been the courage of some of the hotel residents who fought back the terrorists, the death toll could have been a lot higher than its now," Mr Hussein said.

"They came in firing bullets randomly and chanting God is great - they shot anyone they could see," said a surviving hotel resident, Ahmed Abdulle.

Al-Shabab, the Islamic extremist rebels waging an insurgency against Somalia's weak UN- backed government, claimed responsibility for the attack.

Despite being forced out of Mogadishu and many other cities and towns across Somalia, al-Shabab continues to launch lethal attacks in the capital and elsewhere. Al-Shabab is fighting to oust the Mogadishu government and install a strict version of Shariah law.

The extremist rebels killed 148 people in an attack on a college in Garissa, Kenya in April.