Crowds of local people had gathered in the Somalian capital to watch their final moments, excruciatingly drawn out as their former colleagues missed repeatedly and bullets landed all around them in the sand.
It took more than ten rounds of fire to kill the men with one having to be finished off at point-blank range with a bullet in the heart.
The Western-backed regime in charge of Somalia is desperate to prove it has a grip on law and order in the famine-hit state.
But the brutal images will win the country few friends in its efforts to present a credible alternative to the Islamic militants who provide such a threat to security.
Somalia's government recently increased control in the capital Mogadishu after Islamist rebels withdrew. It hopes to gain support for a new humanitarian force to protect food aid convoys.
Judge Hassan Muungaab told Reuters: 'We caught these two soldiers red-handed. One killed a civilian and the other a soldier, so we have decided to execute them in accordance with the laws of Islam and our military court. Read More