A Ugandan military court has found two officers guilty of cowardice as Islamist fighters stormed an African Union base in Somalia in May.
Majors Zadock Abor and John Oluka ran away after they came under attack by al-Shabab in Bulo Marer, south of the capital Mogadishu.
At least 50 Ugandan soldiers were killed, officials say.
Uganda is part of the African Union force helping Somalia’s government fight al-Shabab, an al-Qaeda affiliate.
The attack on Bulo Marer was one of the deadliest for the African Union force, Atmis, since it launched a new offensive against al-Shabab last year.
Uganda’s president, Yoweri Museveni, criticised his military for its response.
The Ugandan military court sitting in Mogadishu heard that the officers had been given warning of an impending attack but failed to act to deter it.
As al-Shabab gunmen stormed the base, they failed to rally their troops and instead ran away to another base.
Both officers have been dismissed from the army.
Four non-commissioned officers were also found guilty of failing to protect military equipment.
The 19,000-strong African Union force was sent to Somalia in 2007 and helped force al-Shabab out of many cities.
It is scheduled to transfer security responsibilities to Somalia’s government forces and leave the country next year.
However, the offensive against al-Shabab has stalled and the group still controls many rural parts of the country.