Al-Shabab said the three men were CIA and MI6 informants, and were the reason several drone attacks killed leaders from the group.
Mohamed Jama, a resident in the coastal town of Merca, told The Associated Press that dozens of masked fighters tied up the three men and killed them by firing squad.
A self-proclaimed militant judge gave the death penalty order. Hundreds of residents were forced to watch and many of them vomited after the killings, Jama said.
“The execution and the verdict were quick and dirty. It was gruesome to watch,” he said. “The men instantly died after their bodies were riddled by bullets.”
A U.S. Embassy spokesman said he was not aware of the executions, but that in general the U.S. does not comment on intelligence matters.
An al-Shabab member, who gave his name as Abu Abdalla, said militants interrogated the men for six months before the executions.
Al-Shabab said on its official Twitter feed the three men “were part of a wide network of spies deployed by the British and American intelligence agencies” to spy on al-Shabab. Al-Shabab said that Western powers can’t coordinate airstrikes without relying on human intelligence.
Dozens of American and British citizens, usually of Somali origin, have joined al-Shabab, and officials in both countries worry that members of al-Shabab holding U.S. or U.K. passports could return to carry out a terror attack in those countries.
The Twitter postings said that two of the accused spies planted tracking devices on a vehicle that was hit by a missile strike on the outskirts of Mogadishu in January. Bilal Al-Berjawi, a British fighter of Lebanese descent, was killed in that strike.
The postings said that Ishaq Omar Hassan, 22, and Yasin Osman Ahmed, 23, worked for the CIA. It said that Mukhtar Ibrahim Sheikh Ahmed, 33, worked for MI6, Britain’s spy agency.
Over the last year, al-Shabab has lost control of Mogadishu and ceded power in towns in western Somalia. The militants have largely either fled to northern Somalia and Yemen, or have retreated to Kismayo and Merca, the last two major towns the militants control.