MAZAR-I-SHARIF (Agencies) - Afghan protesters angered by the desecration of Quran by an obscure US pastor killed up to 20 UN staff, beheading two foreigners, when they overran a compound in a normally peaceful northern city on Friday in the worst ever attack on the UN in Afghanistan. At least eight foreigners were among the dead after attackers took out security guards, burnt parts of the compound and climbed up blast walls to topple a guard tower, said Lal Mohammad Ahmadzai, a police spokesman for the northern region. A police source said the chief of the mission in the city was wounded but survived. Five protesters were also killed and around 20 wounded. The governor of Balkh province said insurgents had used the march as cover to attack the compound, in a battle that raged for several hours and raises serious questions about plans to make the city a pilot for security transfer to national forces. An AFP reporter in Mazar-i-Sharif said the violence continued for three and a half hours, with small arms fire and explosions heard. There were about 500 protesters, the correspondent said. The protesters made a resolution containing 13 items which asked the foreign troops to leave Afghanistan, stop killing of civilians, and untie all diplomatic relations with the United States government, he said. The insurgents have taken advantage of the situation to attack the UN compound, said Governor Ata Mohammad Noor. He told a news conference that many in the crowd of protesters had been carrying guns. Some 27 people have already been detained over the attack, he added. Fridays attack followed a protest march led by religious clerics and attended by around 200 in Kabul on Friday against the Quran desecration and plans announced by Karzai in February for possible permanent US bases in Afghanistan. The demonstrators, who left from mosques in downtown Kabul after Friday prayers, burned a US flag and stamped on it, shouting 'Death to America. Eight foreigners were killed, and two were beheaded, said Ahmadzai. Seven UNAMA employees have been killed, out of which five are Nepalese and two others are Europeans, one woman and one man, Balkh governor Atta Mohammad Noor said, referring to the United Nations Assistance Mission in Afghanistan. The Taliban claimed responsibility for the violence, saying it was the first step in a campaign against the upcoming presidential elections. Accounts of the attack were contradictory but indicated the killings had been carried out in the style of executions. But General Abdul Rauf Taj, a police official in Balkh province, said that according to the initial reports... none have been beheaded. They were shot in the head. Afghan police and army, who the United Nations rely on for their first line of defence, were apparently unable to control the crowd. German troops are also stationed in Balkh, and the NATO-led coalition said they had received a request for help. A United Nations spokesman confirmed employees had been killed but declined to comment on numbers of dead or their nationalities. He said the attack would not push the United Nations out of Afghanistan. We need to secure our colleagues in Mazar-i-Sharif. Its not a question of us pulling out. The UN is here to stay, said spokesman Kieran Dwyer. Staffan De Mistura, the top UN diplomat in Afghanistan, has flown to Mazar-i-Sharif to handle the situation personally. The Russian chief of the mission in the city, Pavel Yershov, was injured in the attack but is now in hospital, Russian state television said, quoting an embassy spokesman. Russia called on the Afghan government and international forces to take all necessary measures to protect UN workers in a statement issued by the foreign ministry after the attack. Romania's foreign ministry said preliminary information suggested a Romanian citizen was among the dead, and condemned the attack. US President Barack Obama condemned the attack in the strongest possible terms, while UN chief Ban Ki-Moon called it outrageous and cowardly. NATO Secretary General Anders Fogh Rasmussen also condemned the attack. If the death toll is correct, it would make it the deadliest attack on the United Nations in Afghanistan, and one of the worst on the organisation for years. The worst previous attack was an insurgent assault on a guesthouse where UN staff were staying in October 2009. Five employees were killed and nine others wounded. The two largest attacks on UN compounds in other countries are a 2007 bomb in Algiers that killed 17 UN staff, and a 2003 attack on the Baghdad hotel that was the UN headquarters there, which killed at least 22 people. Mazar-i-Sharif has remained relatively peaceful as the insurgency gathers force in other parts of the north, and was recently chosen as one of the first areas for a transition of security from NATO troops to Afghan forces. Long-standing anger over civilian casualties has been heightened by the Quran desecration and the recent publication of gruesome photographs of the body of an unarmed Afghan teenager killed by US soldiers. The Quran desecration was denounced by Karzai and Pakistani President Asif Ali Zardari. Thousands of demonstrators marched through western Herat city and around 200 in Kabul to protest against the same incident, but there was no violence at either demonstration. Meanwhile, six American soldiers have been killed in a single operation in eastern Afghanistan over the past two days, a spokesman for the international coalition said on Friday. I can confirm that six coalition soldiers have been identified as US soldiers, and were all killed as part of the same operation, but in three separate incidents, said Maj Tim James. The deaths took place from late Wednesday through Thursday. The operation, a helicopter-borne assault into a remote part of Kunar province close to the Pakistani border, was continuing.