The attack began when a suicide bomber blew himself up near the Amalow Hotel in Bulo-Burte town before gunmen tried to force their way in, said Col Ahmed Ali.
Gunfire could be heard as Ali spoke by telephone. Two AU soldiers were among those killed, said Col Ali Aden, a spokesman for the African Union force.
The Islamic militant group al-Shabab claimed responsibility through an announcement on its radio station.
It’s the second such attack against the hotel. A suicide car bomber and gunmen attacked the hotel in March, killing at least five people. Al-Shabab also claimed responsibility for that attack.
African Union and Somali troops seized Bulo-Burte town in early March from the extremists. Al-Shabab has since stepped up attacks against the troops in the town.
AU forces pushed al-Shabab out of Mogadishu in 2011. The government troops in the last six months have been waging battles outside the capital in smaller towns still held by al-Shabab.