Somalia's Al-Qaeda linked Shebab insurgents shot and blasted their way into the UN compound in Mogadishu on Wednesday, leaving nine people dead in the most serious attack on the United Nations in the troubled country in recent years.
Three foreigners including two South Africans in the UN compound died in the attack along with a Somali UN worker, two Somali security guards and three civilians in the surrounding streets, officials said.
UN Secretary-General Ban Ki-moon said he was "shocked" by the brazen daylight raid while Somali Prime Minister Abdi Farah Shirdon condemned it as a "senseless and despicable attack on innocent UN civilians".
Washington also condemned the attack "in the strongest terms", with a National Security Council spokeswoman saying it "highlights the repugnant terrorist tactics (Shebab fighters) use to stand in the way of efforts to ease the suffering of the Somali people."
The insurgents, who boasted about the killings of "infidels", used a pickup truck laden with explosives and suicide attackers to blast their way into the fortified base.
Government officials said seven Shebab fighters took part in attack, all of whom either detonated suicide vests or were shot dead.
Security warnings of an attack have been in place for weeks, and UN staff regularly practise sheltering in a secure bunker inside the central Mogadishu compound.
"Our commandos attacked the UN compound.... We set off an explosion and entered," a senior Shebab official told AFP, saying they had wanted to attack "the infidel forces".
Somali and African Union troops later moved into the complex -- despite the Islamists battling back with heavy gunfire -- to end the hour-and-a-half siege.
"Somali soldiers along with African Union forces stormed the compound and killed the attackers," said Somali police official Abdulahi Osman.
He said three civilians were confirmed killed, caught in the crossfire in streets near the compound.
UN sources said the others killed included one foreign staff member, one local worker, two South African contractors and two Somali security guards.
South Africa's state-owned military equipment manufacturer Denel confirmed that two of their South African employees had been killed alongside a Somali employee.
All were providing maintenance services to the compound, Denel officials said.
The nationality of the other foreigner could not be immediately confirmed.
An AFP reporter saw several bloodied bodies carried away on makeshift stretchers.
"Some of the 'white kuffar'(unbelievers) who tried to engage the mujahedeen in combat inside the offices were killed and thrown out into the compound," the Shebab wrote on Twitter.
The UN Assistance Mission in Somalia (UNSOM) said the compound -- home to UN humanitarian agencies -- had come under "complex attack", and UN staff elsewhere in the city were temporarily pulled back to the secure airport zone.
The compound -- including both residential and office areas -- is a short distance from the airport zone, the base of the African Union troops, but is guarded by its own security officers.
Somalia's capital has been hit by a series of attacks including suicide and car bombings, mortar attacks and shootings, although in recent weeks the city has been relatively calm.
Islamist Shebab militants used to control most of the seaside capital until they abandoned fixed positions in August 2011, but the insurgents have since carried out a string of attacks against the UN-backed government.
The last major attack was in April, when the Shebab sent a nine-man suicide commando unit to blast its way into Mogadishu's main court complex, killing 34 people.
The attack on the UN compound used similar tactics to the courthouse assault.
The 17,000-strong AU force, fighting alongside Somali government troops, has forced the Shebab from a series of key towns.
While riven by infighting and hunted by US drones, Shebab extremists remain a potent threat, launching car bombs and assassinations, and are still powerful in rural areas as well as reportedly infiltrating the security forces.
Prime Minister Shirdon condemned the attack.
"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," he said in a statement.