A second blast targeted African Union (AU) troops about 25km (15 miles) from the city, but details are sketchy, a BBC reporter says.
Al-Shabab, linked to al-Qaeda, has often carried out attacks in Somalia and neighbouring Kenya.
On Tuesday, it killed 36 quarry workers near the northern Kenyan town of Mandera.
It has not commented on the latest explosions.
'Smoke all around' The United Nations and the British and Italian embassy compounds are based near Mogadishu's heavily fortified airport.
"The explosion was very big and there is smoke all around the area. I can hardly see people lying on the ground, either dead or wounded," witness Shamso Idle told AFP news agency.
Police said at least four people, including a Somali intelligence officer, were killed and about 10 others were wounded in the blast, reports the BBC's Mohamed Moalimu from Mogadishu.
The UN has not reported any casualties among its staff.
Its security personnel were at the site, inspecting the wreckage, our correspondent says.
The explosion targeting AU troops took place in Lafole village, south of Mogadishu, our correspondent says.
The AU has some 22,000 troops helping the weak and divided Somali government battle al-Shabab.
The UN has no troops in Somalia, and says it staff are involved in political activities aimed at helping the government achieve stability.
Various armed groups have been battling for control of Somalia since the overthrow of President Siad Barre in 1991.