Heavy gunfire rang out across central Mogadishu on Friday as Somali troops battled to dislodge insurgents holed up next to a hotel they bombed the previous evening, and as the death toll stemming from that attack neared 30.

Al Shabaab fighters set off two bombs outside the Hotel Maka al-Mukarama before retreating to an adjacent building, from where they fired on soldiers who tried to enter. At least two soldiers were carried away from the hotel on Friday morning.

The attack - the latest in a series of high-profile assaults in East Africa by al-Shabaab - came after US forces in Somalia stepped up airstrikes against the extremist group.

"The militants are still fighting from inside a civilian house adjacent to the hotel... (They) are fighting back with grenades and Kalashnikov (rifles)," police officer Major Musa Ali told Reuters.

He said 29 people, mostly civilians, had died in the attack and its aftermath, and 80 had been wounded. Many civilians had been rescued but the death toll could rise, he added.

Emergency rescue staff carry the body of a victim over rubble at the scene of a car-bomb attack on February 4, 2019 in Somalia capital Mogadishu. (Photo by AFP)

Al-Shabaab's military spokesman said the group was still in control of the Hotel Maka al-Mukarama, which is used by government officials and located on a street lined with hotels, shops and restaurants.

"The government tried three times to enter the building but we repulsed them," said Abdiasis Abu Musab.

Somalia has been convulsed by lawlessness and violence since 1991, and al-Shabaab is fighting to dislodge a Western-backed government protected by African Union-mandated peacekeepers.

The group has also carried out deadly attacks in neighboring countries contributing to the African Union force, including one on a hotel and office complex in Kenya in January that killed 21 people.

Under President Donald Trump, Washington has stepped up attacks against the group, and US Africa Command announced six airstrikes it says have killed 52 militants since February 23.

In northern Somalia, a splinter group of former al-Shabaab fighters who have pledged allegiance to Daesh is also battling the insurgency.

At least 25 people have been killed in the fighting between the two sides this week when al-Shabaab captured three villages from the faction aligned to Daesh, a military official from the semi-autonomous region of Puntland told Reuters.