MOGADISHU (Reuters) - Somalia's militant al Shabaab group said late Friday it had executed four people it accused of espionage, including one who was beheaded for allegedly giving information to the United States that led to the killing of the group's former leader.

The Islamist group wants to topple Somalia's Western-backed government and rule the country according to sharia law.

In 2011, al Shabaab was ejected from Mogadishu by the African Union force AMISOM, and last year it was also pushed out of its southern Somalia strongholds by a combination of AMISOM and the Somali National Army.

In recent months, however, the group has stepped up attacks on AMISOM forces and conducted gun, bomb and suicide assaults on civilian targets in Mogadishu and other towns, underscoring its resilience.

According to al Shabaab's radio, Al Andalus, the four executed men were sentenced to death on Friday afternoon "after they were proved working with (the) CIA, Kenya and Somalia."

"They were publicly executed in a field in Bula Fulay village of Bay region," Al Andalus said, referring to an area in southern Somalia.

Ahmed Nur, a local resident, told Reuters by phone people in the area had been asked by al Shabaab to gather near its camp.

"We thought there was a lecture, however we witnessed three men shot dead and another beheaded in front of us," he said

According to the radio broadcast, the beheaded man was Mohamed Aden Nur, 26, who was accused of "working with (the) CIA" and facilitating the killing of al Shabaab's former leader Ahmed Godane, who was killed in a U.S. drone strike in 2014.

Another of the executed men, Muhaydin Hiraab Ahmed, 27, was accused of spying for the CIA and Somalia's neighbor Kenya, and in aiding the killing of Adnan Garaar.

Garaar, who allegedly masterminded the deadly assault on the Westgate Mall in Kenya's capital Nairobi in 2013, was also killed in a U.S. drone strike in 2015.

(Reporting by Feisal Omar; Writing by Elias Biryabarema; Editing by Mark Potter)