Four auto bombs by Islamic extremists exploded outside a hotel in the capital, Mogadishu, killing at least 20 people and injuring 17, said police.
Twin auto bombs detonated in Mogadishu within moments of each other, followed by gunfire and a third blast a while later.
Guards at Hotel Sahafi and the CID headquarters opened fire following the first two blasts.
"Four militants who attempted to enter the hotel were shot dead by our police and the hotel guards", police captain Mohamed Ahmed told Reuters.
Mogadishu faces frequent bombings at the hands of Al-Shabaab, an Al-Qaeda affiliate which has been fighting to overthrow the internationally backed Somali government for over a decade.
"Two other militants were suicide auto bombers who were blown up by their vehicle bombs".
The militant group al-Shabab, which has waged an insurgency for more than 10 years, said it carried out the attack.
Sahafi Hotel owner Abdifatah Abdirashid was a renowned businessman who took over running the hotel from his father, Abdirashid Mohamed.
A Reuters photographer at the scene saw 20 bodies of civilians and burnt-out minibuses, motorbikes and cars.
Al-Shabab said it targeted government officials staying at the hotel.
Sahafi Hotel has been popular with visiting foreigners because of its relative security as well as its view overlooking Mogadishu.