The force of the explosions shattered windows at Mogadishu's nearby airport, showering arriving passengers with glass, said witnesses.
Al Shabaab, the Islamist militant group fighting to topple Somalia's Western-backed government, claimed responsibility for the attack, saying it had killed more than 12 people.
It regularly reports higher death counts than the authorities.
Police said the first attacker detonated a car bomb and the second tried to storm the base on foot, but was shot and exploded at the gate.
"We understand at least seven from a private security firm died," said Ali Farah, a police officer.The guards were caught in the blast at the gate as they escorted UN personnel into the base, which is known as Halane, he added.
United Nations Mogadishu office staff and Somali soldiers carry the body of a colleague on a stretcher (Getty) Source: Getty Images
The African Union's AMISOM force said on Twitter it condemned the "senseless attacks that aim to disrupt and cripple the lives of ordinary Somalis". There was no immediate comment from the United Nations.
Al Shabaab spokesman Abdiasis Abu Musab said both attackers detonated car bombs.
People arriving on international flights said the blasts shattered windows in the airport buildings.
"We were greeted by two loud blasts. The glass of the airport building fell on us," said Ali Nur, who had just got off a plane from Nairobi.