Al-Shabab militants have attacked a government complex in a busy area of Somalia's capital, Mogadishu, leaving at least 17 people dead, including seven assailants.
A car loaded with explosives was driven into the wall surrounding the compound, and gunmen then stormed the building.
Officials say the attack is now over and the building has been secured.
Al-Shabab opposes the UN-backed administration and wants African Union forces to leave Somalia.
Last month, the al-Qaeda-linked insurgents launched a two-day siege at a hotel in Mogadishu.
And earlier this month, al-Shabab sent shockwaves through neighbouring Kenya when it killed 148 people in an attack on Garissa University.
Tuesday's attack began when a suicide bomber struck the walled compound - which houses the education ministry and other government buildings - in a car laden with explosives.
Gunmen then streamed into the hole in the building's defences and started shooting.
Somali government spokesman Ridwan Abdiweli said a total of 17 people died in the attack.
For the latest news, views and analysis see the BBC Africa Live page.
That includes eight civilians and two soldiers - one from the African Union Mission and the other from the Somali military. Seven al-Shabab fighters also died.
Omar Mohamed, a trader who works near the scene, told Reuters news agency that he was thrown off his chair when the blast went off.
He said attackers sprayed gunfire at security forces as they battled to retake the building.
Witness Idil Malim told the AFP news agency he had seen several dead bodies lying at the scene.
Shooting and the wail of ambulances could be heard, and many injured people were carried away to hospital. Public buses sat abandoned in the street close to the ministry compound.
The ministry's director-general, Ismail Yusuf, was among the injured, state radio reported.
It said the head of security at the ministry, who it named as Sandheere, was among the dead.
Al-Shabab militants often launch attacks in the city and have previously used car bombs to initiate attacks on fortified buildings.
Last week, Somalia placed a bounty on the top 11 leaders of the group.