MOGADISHU (Reuters) - Somali Islamist group al Shabaab shot two men and a teenager in southern Somalia on Tuesday, saying one of the men and the 15-year-old had been seen having gay sex, while the other man was found guilty of spying, a senior al Shabaab official said.

Hundreds of civilians gathered in a field in the town of Buale to watch them being shot, the second time al Shabaab has killed men accused of homosexuality, the official said, without giving details of the previous killing.

Homosexuality and gay sex is outlawed in most of Africa’s 54 states and can be punishable by imprisonment.

“The judge read their charges publicly and the three men were found guilty. They were executed according to the Islamic sharia. They were shot dead in Buale town,” Sheikh Mohamed Abu Abdalla, a regional governor for al Shabaab, told Reuters.

A Somali government official said any case of homosexuality in Muslim Somalia would be dealt with according to sharia law, although he did not specify what that would mean in practice.

Al Shabaab militants are fighting against Western-backed government forces in Mogadishu in a bid to impose its strict interpretation of Islamic, or sharia, law.

The al Shabaab governor said 20-year-old Isak Abshirow and 15-year-old Abdirizak Sheikh Ali were found committing a homosexual act by al Shabaab fighters.

Saeed Mohamed Ali was found guilty of spying for Ethiopian troops, who form part of an African force that has been fighting the militants.

The Islamist group once controlled the capital and much of Somalia but it lost control of Mogadishu in 2011 and has slowly been driven back into smaller pockets of territory since then.