Militants set off two car bombs outside a police base in Somalia's capital before gunmen stormed inside on Sunday, leaving at least 10 people dead, police said.
Islamist group al-Shabaab claimed responsibility for the assault on the headquarters of Somalia's Criminal Investigation Department (CID) in Mogadishu.
It was the second major operation in the city this week by the group which has kept up a guerilla war on the Western-backed government in the face of U.S. drone strikes and African peacekeeping forces.
Heavy gunfire rang out inside for about half an hour after the first blast, said witnesses.
The bodies of four civilians lay in the street near the compound which was partially destroyed. A kiosk close to the wall caught fire.
"At least 10 people including four militants, five civilians and a soldier died in today's attack," Hussein Ali, a police officer, told Reuters.
Another 15 people were injured, some seriously, he added.
Al-Shabaab's military operations spokesman, Abdiasis Abu Musab, said one of its suicide bombers had started the attack by ramming a car bomb into the building's gate.
In al-Shabaab's first attack this week, 13 people were killed when two car bombs went off at the gate of the African Union's main AMISOM peacekeeping base on Tuesday.
Security analysts have warned that the group could step up its attacks, taking advantage of the distraction caused by campaigning for a presidential election due in August.
Al-Shabaab, seeking to impose its harsh form of Islam on the Horn of Africa nation, has also launched attacks in Kenya and Uganda which have contributed troops to the 22,000-strong AMISOM force.
Somalia plunged into anarchy in the early 1990s following the toppling of military dictator Mohamed Siad Barre.