Mogadishu (AFP) - Al-Shabaab Islamists on Wednesday carried out attacks on two Somali military bases, using a suicide vehicle bombing and dozens of heavily armed militants, a military official said.

African Union troops stepped in to help repel the second, larger attack, after a suicide bomber drove a vehicle packed with explosives onto a bridge leading to the Qoryoley army base some 95 kilometres (59 miles) west of Mogadishu and detonated it.

Earlier they had attacked the Ceel-salini military base some 30 kilometres away.

"The terrorists carried out an ... attack on the military bases at Qoryoley and Ceel-salini but our brave boys repelled them, they (Shabaab) have suffered heavy casualties this morning and the army is in full control in the both areas now," said Mohamed Adan, a Somali military commander in a nearby town.

"They have destroyed part of the bridge across the entrance to Qoryoley where the Somali military base is located using a vehicle loaded with explosives."

He said the AU peacekeeping force AMISOM had helped fight the Al-Qaeda linked militants.

It was not yet known how many casualties there were.

Witnesses said dozens of heavily armed Shabaab militants entered Qoryoley town and addressed a gathering of residents before retreating.

"The Shabaab fighters entered the town and one of their commanders spoke with a gathering before they made their way out of the town, the situation is quiet now and the Somali forces backed by AMISOM soldiers are patrolling the streets," Ali Moalim, a resident in Qoryoley said by phone.

Al-Shabaab claimed responsibility for the attack in a statement, saying they had "captured a sizeable amount of military supplies".

The group has fought for over a decade to topple the internationally-backed Somali government, and carries out regular attacks against civilian and government targets, despite losing much of the territory they once controlled.