The Somali armed group al-Shabab has launched an attack on the country's intelligence headquarters in central Mogadishu, setting off a bomb and opening fire on the complex, police and witnesses said.

The car bomb explosion, was followed by a fierce exchange of gunfire killing at least seven rebel fighters, officials said on Sunday.

There were no details on casualties among the security forces.

A spokesperson of the armed group confirmed with Al Jazeera that its fighters were involved in the attack and that they had entered the building.

Ahmed Hussein, a senior police officer, confirmed the attack, and added that the facility included underground cells.

"It seems their target was to cause a mess here and thus free their militant colleagues held in the underground cells, but that will not happen," Nur told Reuters news agency.

That compound is near the national intelligence site, and it was also attacked using what has become a familiar tactic: a vehicle tries to blast its way through perimeter security and gunmen charge in afterwards.

It was the latest in a series of attacks in Mogadishu in recent months, including a July raid on the presidential compound.

The president was not present during the July raid.

Al-Shabab, which wants to impose its own strict version of Islam, controlled Mogadishu and the southern region of Somalia from 2006 to 2011. It was driven out of the capital by peacekeeping forces deployed by the African Union.

African forces launched a new offensive this year to drive the armed group out of towns and other areas they still control.

Several centres have been retaken, but al-Shabaab remains in control of some towns and swathes of countryside.