Islamist insurgents attacked a police station in the heart of Somalia's capital in a night raid as preparations are under way for weekend peace talks.
At least two policemen, two soldiers and a civilian died in the heavy fighting, witnesses said. Police say five insurgents also died, but the Islamists say they lost one.
Correspondents say delegates are on their way to the Djibouti talks, but face-to-face negotiations between the opposition and government are unlikely.
Islamist leader Sheikh Sharif Sheikh Ahmed, who has been based in Eritrea for the last 17 months, has said he will only meet delegates from the international community.
The Union of Islamic Courts (UIC) official told Al-Jazeera TV that he would not talk to the government directly as it had committed human rights abuses.
The UIC ruled much of Somalia in 2006 before being ousted by Ethiopian forces backed by Somali government troops, who have been struggling to exert their control over the country ever since.
Witnesses say more than 100 heavily armed Islamists raided the police station in Mogadishu's Waberi district. They were shouting "God is great" and firing rocket-propelled grenades.
"The fighting was terrifying," resident Hawa Abdi told AP news agency. The militants held the station briefly and then abandoned it, witnesses say.
Al-Shabab, the militant wing of the UIC which is behind much of the latest violence, has refused to attend the talks due to start in Djibouti on Saturday.
They say there can be no negotiations until Ethiopian forces leave. Earlier this week, rights group Amnesty International said Somali civilians are totally at the mercy of armed groups.
It said the situation was "dire" in the centre and the south with government troops, their Ethiopian allies and Islamist insurgents "out of control".