* AMISOM says al Shabaab attacked its troops
* Residents fear militants, government soldiers
* U.N. special envoy says al Shabaab still a threat
By Abdi Sheikh Mohamed Ahmed
MOGADISHU, Aug 7 (Reuters) - Fighting erupted on Sunday in Mogadishu between government troops and al Shabaab insurgents a day after the rebels said they were leaving the Somali capital and the government declared it controlled most of the city, residents and officials said.
A spokesman for the African Union (AU) peace keeping force, AMISOM, said al Shabaab fighters had attacked them in one district late on Saturday, but that they and the government now controlled most of Mogadishu.
After al Shabaab started its withdrawal, President Sheikh Sharif Ahmed said his troops had defeated the rebels intent on overthrowing his Western-backed government.
Al Shabaab, which has its stronghold in the south of the anarchic country, denied this and said it would re-group and fight on.
Somalia has been without effective central government since the fall of dictator Mohamed Siad Barre 20 years ago, and is now suffering mass hunger from the worst drought in decades. Peace remains a distant prospect.
"Last night al Shabaab fired mortars and attacked us... they were not so strong, we chased them immediately," an AMISOM spokesman, Captain Ndayiragije Come, told Reuters on Sunday.
"AMISOM and the government forces now control 90 percent of the capital. We are very sure we shall uproot the few al Shabaab elements remaining in the few parts of the capital."
Residents said the fighting had continued into Sunday and that in some areas al Shabaab fighters had the upper hand.
"Now there is fighting near the football stadium. Organised clan militia and al Shabaab remnants have repulsed the advancing government troops," one resident, Somow Ali, told Reuters by phone from Huriwaa, in the north of Mogadishu.
The U.N.'s special envoy for Somalia, Augustine Mahiga, said al Shabaab remained a threat despite their pullout, and said the priority would now shift to delivering food aid in a country gripped by famine in some areas in the south.
"The immediate priority must now be to focus on the humanitarian situation and I call on all parties ... to do everything possible to ensure and facilitate the immediate delivery of assistance to those most in need," he said.
Al Shabaab's exit from Mogadishu, if confirmed, could mean a change of tactics from military combat against the government and AMISOM troops to al Qaeda-style suicide attacks.
Some Mogadishu residents fear they will come under attack from government troops flushing out al Shabaab remnants. The Islamist militia has in turned threatened to decapitate anyone who turns its fighters in to the police.
"The al Shabaab's camouflaged departure and the advancing government are two newly modified threats," local elder Gele Bixi told Reuters.
"Jihadists will continue (with their) blasts and beheadings and the so-called government forces will have the chance and space to rape and rob. We have no near future to talk about." (Writing by George Obulutsa; Editing by James Macharia and Alistair Lyon)