The Al-Qaeda linked insurgents ambushed Ugandan troops that are part of an African Union force as they patrolled a supply route in the hotly-contested Lower Shebelle region, the military said in a statement.
"From the battlefield, it is now confirmed that UPDF lost 12 gallant soldiers with seven sustaining injuries," the statement from the Uganda Peoples' Defence Forces said.
Witnesses told AFP the attack occurred in the village of Golweyn, some 120 kilometres from the capital Mogadishu.
The AU mission AMISOM said an improvised explosive device (IED) was used in an ambush of a convoy composed of its troops and Somali forces.
More From This Section
A Shabaab spokesman yesterday told a radio station linked to the group that the insurgents had killed 39 soldiers, a claim that could not be independently verified.
The AU has a 22,000-strong force in the country dedicated to fighting Shabaab and supporting the internationally backed government.
Shabaab has fought governments in Mogadishu for years and has also carried out attacks in Kenya and Uganda.