The United Nations mission in Afghanistan has been plunged into jeopardy after protesters enraged by the burning of a Qur'an by Christian extremists in the US stormed a UN compound in the north of the country and killed at least seven foreign staff members.

Amid uncertainty about the overall death toll, the UN said its staff were killed when the usually peaceful city of Mazar-e-Sharif exploded into violent protest.

Four of the seven foreigners killed were former Gurkhas working as private security guards. Norway's defence ministry named another victim as Lieutenant Colonel Siki Skare, a 53-year-old female pilot working for the UN, while the sixth victim was named as Joakin Dungel, 33, a Swede working in the UN office. The seventh foreigner killed was believed to be Romanian. Two of the UN workers were reported to have been beheaded

Last night, Afghan officials arrested more than 20 people in connection with the assault including the alleged ringleader.

Under UN rules, officials will have to consider pulling out staff members or shutting down operations altogether.

After an attack on a UN guesthouse in Kabul in late 2009 in which five UN staff were killed, hundreds of their colleagues were temporarily relocated to Dubai while the organisation spent millions closing guesthouses and outfitting a big base on the outskirts of Kabul.

Last night, Staffan de Mistura, the UN's leading envoy in Afghanistan, flew directly to Mazar-e-Sharif to take stock of the disaster. One senior staff member said there had been "absolutely no discussion" about repositioning staff, but many UN workers feared the incident would mark another milestone in the gradual retreat of UN diplomats and aid workers into a world where they only see the inside of fortified compounds and armoured vehicles.

Last week Hamid Karzai, the Afghan president, said Mazar-e-Sharif would be one of the first areas to be transferred to Afghan control this year. But the police were no match for the sudden outburst of violence yesterday, which was triggered by the actions of a fringe Christian group on the other side of the world.

The Rev Terry Jones's small church, the Dove World Outreach Centre in Florida, had threatened to destroy a copy of the Qur'an on the anniversary of the September 11 attacks last year, but the pastor backed down after an appeal by General David Petraeus, the commander of US forces in Aghnaistan. But the church went through with the burning last month with Jones in attendance.

The Qur'an burning was the subject of anger at Friday prayers around Afghanistan yesterday. In Mazar-e-Sharif thousands of people poured out of the city's famous Blue Mosque after a sermon by the presiding mullah, with one police official estimating that there were 4,000 people on the streets of the city.

The head of the Blue Mosque, Atiqullah Ansari, said only a minority were responsible for the violence, claiming they were the followers of a mullah who served under the Taliban regime. "They went to the UN compound and killed the foreigners, this is what they wanted," he said.

Last night Jones told the BBC he could not be held responsible for the attack on the UN. Instead he blamed Islam. "We must take a serious, serious look at Islam," he said. "It's a violent religion that promotes acts of violence, I believe we need to bring this before the UN."

Barack Obama condemned the attack, saying: "We stress the importance of calm and urge all parties to reject violence and resolve differences through dialogue."

The attack was also condemned by William Hague, the foreign secretary, who said: "The families and friends of those killed today have my deepest sympathies. The work of the [UN] in Afghanistan is of utmost importance. It is vital that they can carry out their work in a safe and secure environment.

"I call upon the Afghan government to investigate this incident and bring the perpetrators to justice."

However, in Mazar-e-Sharif the surviving UN staff were said to be shell-shocked and bewildered at the failings of security that allowed their compound to be overwhelmed.

Across the country the UN issued a "White City" order, putting all staff members into a state of lockdown, preventing them from leaving their compounds.