Survivors described chaotic scenes in which guests at the Dayah hotel hid under beds and others jumped out of windows of the four-story building to escape the attackers. Government officials often stay at the hotel.

"They kicked down room doors and at some point posed themselves as rescue teams by telling those inside to come out (only) to kill them," said Hassan Nur, a traditional Somali elder.

The four attackers were also killed. At least 43 people were hurt, Abukadir Abdirahman Adem, head of the ambulance service, told AFP.

The assault on the hotel started when a suicide car bomb exploded at its gates. A second explosion soon followed.

Dozens of people, including lawmakers, were thought to have been staying at the hotel at the time of the morning attack, said Capt. Mohamed Hussein.

A nearby shopping center caught fire and dozens of people helped save goods from the flames.

Somalia's homegrown Islamic extremist group al-Shabab claimed responsibility for the attack via its online radio, Andalus, saying its fighters succeeded in entering the hotel. Soon after the siege ended, emergency officials initially said the attackers had killed eight people.

Al-Shabab frequently targets hotels and other public places often visited by government officials and foreigners. Al Qaeda's East African affiliate is fighting to impose a strict version of Islam in this Horn of Africa nation.

In June, gunmen stormed the Nasa-Hablod hotel, killing at least 14 people. Two weeks before that, gunmen killed 15, including two members of parliament, at the Ambassador hotel.

Despite being ousted from most of its key strongholds, al-Shabab continues to carry out deadly guerrilla attacks across large parts of south and central Somalia.

Earlier this month, a bomb explosion at a restaurant in Mogadishu killed three, and a suicide bomber detonated an explosives-laden vehicle at a security checkpoint near the international airport, killing at least three. That blast occurred a few hundred yards from the main base of the African Union peacekeeping mission.

Al-Shabab's assaults have threatened this nation's attempts to rebuild from decades of chaos. The presidential election, a key step toward recovery, already has been delayed several times because of security and other concerns.