African Union (AU) and government troops launched an offensive against Islamist insurgents in the Somali capital on Friday, seizing rebel bases beyond the city's limits for the first time, the AU force said.

Supported by tanks, the AU's AMISOM force said it had driven the insurgents' out of the coastal city's Mogadishu University as well as the Barakaat cemetery, leaving the two sites under government control.

This is the first time AMISOM has been able to secure an area outside the parameters of the city, allowing them to defend greater Mogadishu from the exterior, Paddy Ankunda, AMISOM force spokesman, said in a statement.

The al Shabaab militants, who pulled most of their fighters out of the capital in August but still hold pockets of territory on the northern outskirts, acknowledged losing ground but said they had trapped the advancing force.

A Reuters witness heard heavy gunfire shortly before encountering a damaged 4x4 car in a narrow, sandy street. Five government soldiers had been killed, including a commander.

Moments earlier, an armoured vehicle ferrying five wounded peacekeepers away from the battle zone had passed, its front tyres blown out and its smashed windscreen stained with blood.

Tanks and armoured vehicles were called in to reinforce the troops ambushed by al Shabaab fighters.

Now we have besieged the Mogadishu University building and we swear these AMISOM forces will not have a way out, Sheikh Abdiasis Abu Musab, the spokesman for al Shabaab's fighters, told Reuters.

Al Shabaab said they had killed 13 Ugandan peacekeepers, an allegation Ankunda denounced as lies, although he acknowledged one soldier was likely to die from his wounds.

The al Qaeda-linked rebel group has waged a bloody five-year campaign to topple the Western-backed government.

Its withdrawal from Mogadishu handed almost total possession of the city to the government, but al Shabaab have increasingly resorted to detonating bombs and suicide attacks, undermining confidence in the government's ability to protect people.

The insurgents are though on the back foot, analysts say, battling Kenyan and Ethiopian forces in southern Somalia, while a food crisis, largely in areas under their control, has weakened popular support.

Somalia and its neighbours want to capitalise on this weakness as Mogadishu works towards drafting a new constitution and holding elections by August this year.

(Additional reporting by Abdi Sheikh; writing by Richard Lough; editing by Philippa Fletcher)