Somalia's Al-Qaida-linked Shebab militants on Tuesday blasted their way into the higher education ministry with a car bomb before storming the building, killing nine people.

Police and witnesses said the car bomb caused a huge explosion which allowed the gunmen to force their way into the fortified building.

"One policeman and eight civilians were killed in the attack, and a dozen others were wounded including a senior education ministry official," police officer Mohamed Dahir said.

Police regained control of the building after around an hour-long attack, which began when "a car loaded with explosives rammed the gate," Dahir added.

Witness Idil Malim said bodies of those killed and wounded lay around the complex.

"There were several people lying dead at the scene," he said.

Shebab spokesman Abdulaziz Abu Musab claimed responsibility, boasting that their gunmen had been in "fully in control" of the ministry, as well as entering a neighboring building housing the oil ministry.

As government forces retook the compound and fighting ended the fate of the gunmen was not immediately clear; whether they had been killed in the assault or had managed to escape.

The building is in the K5 district of the capital, which has been hit by a string of similar attacks in recent months.

The Shebab rebels stage regular attacks in the capital as part of their fight against the country's internationally-backed government and African Union forces supporting it.

A car bombing to force entry into fortified buildings followed by an armed raid has become a trademark tactic of the hardline Islamists.

Somalia has been unstable since the collapse of Siad Barre's hardline regime in 1991, and the country's new government is being supported by a 22,000-strong African Union force that includes troops from Burundi, Djibouti, Ethiopia, Kenya and Uganda.

Shebab fighters have carried out a string of revenge attacks in neighboring countries, notably Kenya and Uganda, in response to their participation in the AU force.

It carried out its deadliest attack yet earlier this month, when Shebab gunmen massacred 148 people in a day-long siege of a university in Kenya's northeastern town of Garissa.

The attack on the university was the Shebab's bloodiest massacre and Kenya's worst since the 1998 bombing of the U.S. embassy in Nairobi.

The Shebab later warned of a "long, gruesome war" unless Kenya withdraws its troops from Somalia, as well as warning the government in Mogadishu it would continue to attack them on home soil.

Shebab fighters also carried out the Westgate shopping mall attack in Nairobi in September 2013, a four-day siege which left at least 67 people dead.

Last month Shehab gunmen in Mogadishu stormed the fortified Maka al Mukarama hotel, used by politicians, diplomats and businessmen.

Despite losing significant territory in recent months the Shebab group, whose name means "youth" in Arabic, still manages to launch frequent attacks as part of its fight to overthrow the government.

Last week the government in Mogadishu issued bounties for 11 top leaders of the Shebab, with $250,000 offered for the extremist's chief, Ahmad Umar.