By Abdi Sheikh and Abdirahman Hussein
MOGADISHU, Aug 31 (Reuters) - Islamist rebels blew up a car bomb and gunmen attacked a national intelligence site in Somalia's capital where suspected militants are held, in an assault on Sunday that left at least 12 people dead.
Three soldiers and two civilians were killed along with seven militants, including the suicide bomber who detonated the vehicle packed with explosives, government officials said.
After the initial blast, gunmen stormed the compound but did not reach the underground cells where suspected militants were being detained, Security Ministry spokesman Mohamed Yusuf told reporters at the site.
One intelligence officer, who identified himself only as Nur, told Reuters the gunmen had entered one building, forcing security personnel to fight room-to-room to clear them out. "All the attackers perished in the end," Nur said.
"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 said.
Some of the attackers wore stolen uniforms of the security forces, the Information Ministry said in a statement, adding that all the militants were killed with 45 minutes of the attack starting. It said the two civilians killed had been passers-by.
Sheikh Abdiasis Abu Musab, al Shabaab's spokesman for military operations, told Reuters the group was behind the attack, the latest in a series of raids in Mogadishu in recent months, including a July assault on the presidential compound.
"For a long time innocent Muslims have suffered in the dungeons of that prison, subjected to torture and humiliation," he said in a statement, adding the raid was "in retaliation and as just punishment for the apostate criminals."
Abu Musab said 15 members of the security forces were killed. Al Shabaab's death toll after attacks is usually much higher than the numbers given by officials.
The presidential compound, which is situated near the national intelligence site, 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.
The president was not present during the July raid.
Al Shabaab, 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 Islamists 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. (Additional reporting by Feisal Omar in Mogadishu; Writing by Edmund Blair in Nairobi; Editing by Rosalind Russell)