Mohamed Abdi, a police officer, told Xinhua the explosion which could have been targeting a government vehicle went off near a mosque in the northern district of Karan in Mogadishu.
"I can confirm four people died and nine others were injured. The explosion went off near a mosque in Sana'a junction in Karan," Abdi told Xinhua.
Witnesses said a government vehicle which had just passed the area could have been the target.
"The blast happens seconds after a government vehicle passed by," Omar Muhidin, a resident, said.
Aamin Ambulance director Abdilkadir Abdirrahman told Xinhua they had ferried the injured to hospitals in the city.
"We have managed to take nine people to hospitals around. We also carried two bodies," Abdirrahman said.
The blast came amid increased attacks in the city in the past weeks, some of which were claimed by the militant group al-Shabab. No group has yet claimed responsibility for the latest incident.