Somali Islamist fighters on Friday beheaded seven prisoners accused of abandoning the Muslim faith and spying for the government in the largest mass execution since the Islamists were pushed from power two and a half years ago.

The public killings in the southwestern town of Baidoa followed weeks of fierce fighting as the Islamists try to seize Somalia's capital, Mogadishu, amid mounting concerns about the influx of hundreds of foreign fighters to the failed state.

The beheadings may be linked to the Islamists' failure to take Mogadishu after a 2-month-old offensive, said a senior analyst at global intelligence company Stratfor.

"Al-Shabab is reacting to a setback," said Mark Schroeder.

The U.S. considers al-Shabab a terrorist group with links to Al Qaeda, which al-Shabab denies. The group controls much of Somalia and its fighters operate openly in the capital.

Last month, the Obama administration announced that it would bolster efforts to support Somalia's embattled government by providing money for weapons and helping the military in neighboring Djibouti train Somali forces. An administration review of U.S. policy toward Somalia found an urgent need to supply the Somali government with ammunition and weapons as it struggles to confront increasingly powerful Islamic militants.

Government troops and African Union peacekeepers only hold a few blocks of Mogadishu, but they still control key government buildings as well as the port and airport, allowing them to receive arms shipments.

Schroeder said elements of the insurgency, always prone to splits, may have wanted to make a public show of strength after the failure to decisively capture Mogadishu.

Somalia's mostly clan-based militias frequently switch sides in the chaotic violence -- the current president and the head of the insurgency were allies two years ago -- and there have been signs of a power struggle in the area where the executions occurred.

Baidoa resident Madey Doyow, who spoke to members of the al-Shabab militia guarding the seven headless bodies, said the gunmen told him some of the executed men had links to pro-government militias.

The victims' frightened, weeping sisters and wives arrived at the police station in Baidoa on Friday to collect the mutilated bodies.

A woman named Miriam, who asked that her last name be withheld to protect her from reprisals, sobbed as she said in a telephone call that four bodies, including her husband's, had been brought to the police station. The location of the other three was unclear.

Hawa, who also wanted her full name withheld, was at the police station with six other families who had been informed a relative had been executed. She told The Associated Press that her brother had been missing for about 20 days after being abducted from his house by masked men, and that she had just been informed that he had been beheaded.

Al-Shabab militia officials told her that the seven had been accused of either renouncing the Islamic religion or spying for the government, she said.

Punishments such as stonings, amputations and beheadings are historically rare in Somalia, which traditionally practices moderate Sufi Islam. But a more extremist form of jihadi Salafist Islam with its roots in Saudi Arabia has taken root during the chaotic warfare of recent years, strengthened by a recent influx of hundreds of foreign fighters.

Adherence to the strict form of Islam helped fighters attract outside funding and help build alliances between rival clans. An emphasis on traditional Islamic law also won support from many Somalis tired of being terrorized by bands of teenage gunmen. In 2006, an Islamist alliance seized the capital and much of the south and ruled for six months before being chased from power and launching the insurgency.

In the past year, the militants have reconquered key towns and swathes of the country, where they have carried out several whippings, amputations or executions. Among the incidents documented by Benedicte Goderiaux, a Somalia researcher for Amnesty International, are the stoning to death of a 13-year-old girl accused of adultery; the stoning to death of a man accused of rape, and several amputations of men accused of theft.

She believes the punishments serve dual purposes: they discourage potential rivals for power and reclaim the law-and-order mantle that first won the Islamists popular support. Somalia's last functioning government was overthrown in 1991, and since then the country has been fought over by packs of warlords.

"It's definitely linked to al-Shabab wanting to show or portray themselves as restoring law and order in the region they control," Goderiaux said. But "it's also linked to them wanting to terrorize the population under their control under the guise of applying sharia law."