Somali and African Union forces have regained control of a UN compound in the Somali capital, Mogadishu, after it was attacked by gunmen, killing at least 15, according to officials.
The gun battle lasted an hour-and-a-half that followed an explosion at the site killing at least four foreign security staff, the Somali government said on Wednesday.
Somali Interior Minister Abdikarim Hussein Guled told reporters: "So far we have confirmed four UNDP [UN Development Programme] foreign staff who were responsible for security, four Somali guards and seven militants."
The al-Shabab armed group claimed responsibility for the attack.
A plume of thick black smoke was seen billowing into the sky after the initial explosion was heard at approximately 11:30am local time (08:30 GMT) on Wednesday.
UN Secretary-General Ban Ki-moon, who is currently in China for talks with the country’s leaders, was "shocked" at the news of the attack, his spokesman said.
"The Secretary-General is aware of the attack against the United Nations in Somalia, and he is shocked by it," Martin Nesirky, the spokesman, said in an e-mail.
"He is being updated regularly as we get more information from Mogadishu and UN Headquarters in New York."
A UN official, who cannot be named because she is not authorised to speak to the media, said the attack was against a building just outside the secure airport compound where all the UN agencies were based. The compound includes both residential and office areas. UN staff took shelter in a bunker at the compound, UN staff told Al Jazeera.
Nicholas Kay, the UN secretary-general's special representative to Somalia, confirmed to Al Jazeera that "a complex attack" had taken place at the compound, but that "the vast majority of UN staff" were safe.
"It did begin with an explosion at the main gate followed up by armed attackers entering the compound where they attempted to assault our staff," he said.
Government-run Radio Mogadishu reported that the attack had started after a suicide bomber blew himself up at one of the gates of the complex.
UN back in Mogadishu
Somalia's capital has been hit by a series of attacks including suicide and car bombers, mortar attacks and shootings, although in recent weeks the city has been relatively calm.
Al-Shabab fighters used to control most of the seaside capital until it abandoned fixed positions in August 2011, but the armed group has since carried out a string of attacks against the UN-backed government.
UN Secretary-General Ban Ki-moon visited Mogadishu last December and announced that the UN would re-open its offices in the seaside capital. The UN began the process of moving its personnel from nearby Nairobi, Kenya, back to Mogadishu, a process that has accelerated in recent weeks.
International embassies - from Turkey and Britain, for example - followed.
The 17,000-strong AU force, fighting alongside Somali government troops, has forced al-Shabab from a series of key towns.
Wednesday's attack, though, underscores the fragile security situation and will force the UN and embassies to review their safety plans and decide if they have enough defences to withstand a sustained al-Shabab assault.
Abdi Farah Shirdon, the Somali prime minister, condemned the "senseless and despicable" attack on Wednesday, saying "the UN are our friends and partners, and the UN agencies offer us humanitarian help and support, so I and all Somalis are appalled that they should be the target and victims of such barbaric violence".