The resident, who gave his name only as Mohammed, said dozens of residents watched as masked militants from al-Shabab killed the two men late Thursday in the town of Bararwe, in southern Somalia.
A self-proclaimed judge for the group read out the verdict against the two men. The judge said the two men had admitted to charges of spying.
Al-Shabab's ad-hoc courts often carry out executions and other draconian punishments like amputations.