NATO on Saturday pulled all its staff out of Afghan government ministries after two US military advisors were shot dead in the interior ministry, as anti-US protests raged for a fifth day.
Taliban insurgents claimed responsibility for the shooting, saying it was in revenge for the burning of Korans at a US-run military base -- an incident that forced US President Barack Obama to apologise to the Afghan people.
In a day of violence across the country, a UN compound came under attack by thousands of demonstrators in northeastern Kunduz province, but they were driven back when police fired into the crowd, an AFP correspondent at the scene said.
Five people were reported killed in the attack, taking the five day death toll from protests over the burning of Korans at the US-run Bagram airbase to around 30.
President Hamid Karzai issued a statement urging demonstrators and Afghan security forces to exercise restraint, saying the government was pressing the US "on the need to bring to justice the perpetrators of the crime".
The two American military advisors from the International Security Assistance Force (ISAF) were in the interior ministry when "an individual" turned his weapon against them, NATO said, without giving further details.
A government source told AFP the two men were killed by a member of the Afghan police.
"For obvious force protection reasons, I have... taken immediate measures to recall all other ISAF personnel working in ministries in and around Kabul," said General John Allen, commander of NATO's International Security Assistance Force.
"We are investigating the crime and will pursue all leads to find the person responsible for this attack."
Obama thanked Allen for "all of the measures he is taking to protect our service members and civilians in Afghanistan and to encourage calm," the White House said in a statement.
The Pentagon said the killings were "unacceptable" and called on Afghan authorities to better protect coalition forces and curtail raging violence.
The US, which leads a 130,000-strong military force fighting an insurgency in Afghanistan, has advisors throughout the Afghan government.
Britain said its embassy was also temporarily withdrawing all civilian mentors and advisors from Afghan government institutions in Kabul.
The latest deaths come hard on the heels of the killing of two American troops on Thursday when an Afghan soldier turned his weapon on them at their base in eastern Nangarhar province as demonstrators approached.
The Koran burning has inflamed anti-Western sentiment already smouldering in Afghanistan over abuses by US-led foreign troops, such as the release last month of a video showing US Marines urinating on the corpses of dead Afghans.
Four French soldiers were shot dead by an Afghan army colleague at their base in Kapisa province in late January shortly after that video was released.
Violent anti-US protests have seen furious Afghans attack French, Norwegian, UN and US bases, shouting "Death to America" after the Taliban exhorted their countrymen to kill foreign troops to avenge the Koran burning.
There were fresh protests in five different Afghan provinces Saturday over the burning of the Islamic holy book at the US airbase at Bagram near Kabul.
In the assault on the UN compound in Kunduz, five people were killed and 66 wounded, including 11 police, health ministry officials and police said.
The UN Afghanistan mission issued a statement thanking the police for their "timely response" and regretting their casualties.
"Although caused by legitimate defence, the United Nations also regrets the casualties among the demonstrators and expresses condolences to the families of those who lost their lives," it said.
It also called on protestors to "reject calls to violence ... in order not to allow the enemies of peace to take advantage of the situation."
In Mihtarlam, in the central province of Laghman, hospital officials told AFP 15 protesters had been brought in with gunshot wounds.
Rallies elsewhere in Afghanistan were largely peaceful, however, authorities said, with protesters chanting "Death to America" and "Long live Islam".
Karzai's government and the US-led NATO force have appealed for calm and restraint, fearful that Taliban insurgents are trying to exploit the anti-American backlash.