Somali Islamist militants drove a car bomb at a hotel in a town in central Somalia that was being used by African Union and Somali military forces, a resident and the militant group said.
The al Qaeda-linked al Shabaab movement said its raid on Monday claimed many lives, but poor communications in that region made it difficult to verify numbers.
The insurgent strike followed an attack on a military convoy near the capital Mogadishu, also on Monday, which killed four Somali soldiers, an army captain said.
Somalia's African Union peacekeeping force AMISOM, now bigger after Ethiopian troops joined this year, has launched an offensive to clear territory still held by al Shabaab.
The Islamists have responded with more guerrilla assaults and have threatened attacks on contributors to the African force, such as Kenya and Uganda. Both those nations have warned of threats and Kenya detained two would-be bombers this week.
Hussein Nur, a resident in Somalia's central Bulobarde town, said a car bomb exploded late on Monday at the Camalow hotel, then troops and militants fought for several hours. His line cut before he could provide further details.
AMISOM could not immediately be reached for comment.
"First, a mujahid (holy warrior) with a car bomb entered the hotel, followed by two well-armed fighters who sprayed bullets," said Sheikh Abdiasis Abu Musab, Al Shabaab's military operation spokesman, told Reuters on Tuesday.
He said 32 soldiers were killed. In the past, al Shabaab has exaggerated numbers while officials have downplayed losses.
Al Shabaab, which is seeking to impose its version of Islamic law, was driven out of bases in the capital more than two years ago, but has continued to control swathes of countryside and smaller towns, which it uses as launchpads to strike.
Regional nations and the West worry that, unless al Shabaab is denied the use of such territory, it will be able to plan strikes well beyond Somalia's borders, such as the attack on a Kenyan shopping mall last year that killed at least 67 people.
Al Shabaab said it carried out that attack to punish Kenya for sending troops to Somalia. Kenya said it had arrested two suspected al Shabaab militants on Monday with bombs that might have targeted the coast which is popular with tourists.
In Uganda, the police said it had intelligence that al Shabaab was planning to attack fuel trucks in transit or at fuel depots or stations in the country.
Authorities in Kampala, where al Shabaab launched bombings during the World Cup in 2010 and killed 77 people, said they would now escort trucks in some areas.
Bulobarde, controlled by al Shabaab until last week, lies about 210 km (130 miles) north of Mogadishu, where al Shabaab has carried out frequent raids on targets that follow similar pattern, with a car bombing followed by an assault by gunmen.
Al Shabaab told Reuters the suicide bomber and a militant gunman were killed in the Bulobarde attack.
The earlier attack on a convoy of AU and Somali soldiers took place next to a military base at Arbis, near Mogadishu.
Somali army captain Ahmed Aden said four soldiers were killed. Al Shabaab's Abu Musab claimed a higher toll, and also said other nationalities died, but this could not be confirmed.
(Additional reporting by Feisal Omar in Mogadishu and Elias Biryabarema in Kampala; Writing by Edmund Blair; Editing by Richard Lough and Andrew Heavens)