At least 15 people, including four foreigners, have been killed in an assault by militant Islamists on a UN office in the Somali capital, Mogadishu, a government minister says.
The gun-battle inside the office lasted for more than an hour, witnesses said.
A cameraman outside the UN Development Programme office told the BBC a suicide bomber blew up a car at its entrance and he saw four gunmen enter.
The al-Qaeda-linked group al-Shabab said it was behind the attack.
Officials say pro-government forces have now secured the compound.
The UN has only recently expanded its operations in Mogadishu after years when its Somalia mission was based in neighbouring Kenya because of security fears.
This is the first time the UN offices have been attacked since it relaunched its mission in Somalia.
The UN Development Programme office is next to the heavily fortified airport in southern Mogadishu.
"A suicide bomber blew himself up at the gate of the UNDP and then several armed fighters went in and opened fire," a senior police official told the Reuters news agency.
Interior Minister Abdikarim Hussein Guled said at least 15 people had been killed - four foreign security workers, four local guards and seven militants.
Two of the dead worked for South African state weapons firm Denel, the company says.
The UK Foreign and Commonwealth Office says it is looking into reports that three British nationals are among the dead.
The al-Shabab Twitter feed says it killed 16 UN workers, including three Britons, two Kenyans and a South African during the attack.
A police official told AFP that three civilians also died after being caught in crossfire.
The cameraman, who asked not to be named for security reasons, told the BBC Somali Service that he had personally helped three people to a military ambulance.
Local residents have fled and some buildings were seriously damaged after the vehicle exploded, he said.
'Moved to bunkers'
As the cameraman was talking to the BBC at about 09:30 GMT, gunshots could be heard in the background.
He said a number of security experts had joined the African Union (Amisom) and Somali soldiers in tackling the militants.
Just after 10:15 GMT al-Shabab said on its Twitter feed: "We've just contacted the Mujahideen inside the #UNDP and they are still fighting some western mercenaries inside the compound."
Later it said it had killed some foreigners in the raid.
"The situation is under control now... Somali soldiers along with African Union forces stormed the compound and killed the attackers," Somali police official Abdulahi Osman told the AFP news agency.
Amisom described the attacked as "cowardly" and Somali Prime Minister Abdi Farah Shirdon Saaid praised the speed of the security forces' response.
"Somali and Amisom security forces responded immediately to the situation after the initial explosion and have brought the situation under control. Sadly we must wait to hear the full details and confirmation of any casualties," he said in a statement.
"All our thoughts and prayers are with our UN colleagues today. But al-Shabab will not derail the peace process. They will not stop our recovery. Violence will not win."
Earlier a UN official told the Associated Press news agency that during the sustained firing all staff were "moved to the bunkers where it's safe".
Andrew, an aid agency worker staying at a nearby hotel, witnessed some of the fighting.
"When I heard the explosions I went up onto the roof of the Jazeera Hotel," he told the BBC.
"There were six mini-explosions. We saw UN troops on the roof of their compound shooting down at the attackers. An RPG-7 hit the hotel, it hit the side wall on the fifth floor."
Al-Shabab, which had been in control of parts of Mogadishu for more than two years, withdrew in August 2011 under pressure from pro-government forces, but continues to launch occasional suicide attacks in the city.
It has also been pushed out of other cities, but still remains in control of smaller towns and large swathes of the countryside in central and southern Somalia.
The improving security situation has prompted the return of Somalis from the diaspora and allowed UN agencies and foreign embassies to return to the country.
Some 18,000 AU troops are in the country supporting the government of President Hassan Sheikh Mohamud who was elected by MPs last September.
His administration is the first one in more than two decades to be recognised by the US and the International Monetary Fund (IMF).