The UN vowed an attack that left seven of its staff dead amid fresh protests over a Koran burning in the United States would not derail its work in Afghanistan during a "crucial period" for the nation.
The attack in the northern city of Mazar-i-Sharif came during a demonstration on Friday against the burning of the Muslim holy book and was followed by demonstrations in southern Kandahar that left 10 people dead.
The assault on the UN compound raises fresh concerns over plans by President Hamid Karzai and the international coalition to hand control of security in Mazar-i-Sharif, along with six more areas, to Afghan forces from July 1.
Following the violent protests President Barack Obama condemned the Koran burning, calling it an act of "extreme intolerance and bigotry".
Friday's attack on the UN was the worst in Afghanistan since the Taliban were toppled in 2001 but special representative Staffan de Mistura vowed the organisation's work in Afghanistan would not be affected.
"This should not deter the UN presence, activities, in this country in this delicate and particularly crucial period," he said.
The remaining foreign staff from the compound, which was set ablaze in the mob attack, would be temporarily moved to Kabul, he said, but would return as soon as a secure office was established in Mazar-i-Sharif.
"This is not an evacuation. We will watch and monitor the situation everywhere in the country... and I will then decide on relocations inside the country -- not outside the country -- depending on the circumstances," he said.
De Mistura blamed insurgents from outside Mazar-i-Sharif for the deadly attack claimed by the Taliban, criticising police for failing to prevent the violence.
Giving the first full account of the attack, de Mistura said armed rebels had infiltrated street protests.
"Some insurgents, probably between seven and 15... had infiltrated the demonstration," de Mistura told reporters late Saturday in the Afghan capital Kabul.
De Mistura was also critical of authorities, saying police were taken by surprise when violence broke out.
"It's clear that if the Afghan police had had a cordon of separation between the demonstration and the building, the building would not have been attacked," he said.
Between 2,000 and 3,000 demonstrators had taken to the streets after the traditional Friday prayers.
The insurgents began throwing stones at the UN compound before storming it, and overwhelmed the guards, killing four.
"The police were not able to stop them and the (Nepalese) Gurkhas did not shoot at them -- the UN don't shoot at crowds, even if they are threatening -- and therefore they took over," he said.
De Mistura said the three Europeans were shot after fleeing to a secure room within the UN compound, which the attackers succeeded in entering.
"What I reconstructed is... those who actually killed my colleagues were the infiltrators. They had handguns... and my colleagues were killed by handguns, all three of them. So I assume it was the infiltrators," he said.
One had his throat cut with a knife after being shot, he added.
The head of the UN office, a Russian national, survived the attack by pretending to be Muslim and speaking the local language Dari.
Sweden named one of the civilians killed as 33-year-old Joakim Dungel. Norway said Lieutenant Colonel Siri Skare, a 53-year-old female pilot, was killed, while diplomats said the third European killed was a Romanian.
While four guards died, two more escaped, as did two Afghan UN workers.
De Mistura said seven or eight people had been arrested over the attack, and some of them appeared to be rebels from elsewhere.
Friday's attack was the worst suffered by the world body since a bomb blast at the UN compound in Algiers in 2007 in which 17 staff died.
The Kandahar protests on Saturday began in the centre of the city and spread as police clashed with crowds marching towards the UN offices and provincial administration headquarters, witnesses said.
Kandahar is the spiritual heartland of the Taliban, who have fought an insurgency against Karzai's government and its Western allies since they were ousted by the US-led invasion.
As well as condemning the Koran-burning, Obama also reiterated his condemnation of the "outrageous" attacks by protesters as "an affront to human decency and dignity."
Before Friday's violence Afghanistan condemned the "disrespectful and abhorrent" burning of the Koran at the Dove World Outreach Center, an evangelical church in Florida, calling it an effort to incite tension between religions.
De Mistura called the Koran burning an "insane and totally despicable gesture".