MAZAR-I-SHARIF, Afghanistan — Stirred up by three angry mullahs who urged them to avenge the burning of a Koran at a Florida church, thousands of protesters on Friday overran the compound of the United Nations in this northern Afghan city, killing at least 12 people, Afghan and United Nations officials said.

The dead included at least seven United Nations workers — four Nepalese guards and three Europeans from Romania, Sweden and Norway — according to United Nations officials in New York. One was a woman. Early reports, later denied by Afghan officials, said that at least two of the dead had been beheaded. Five Afghans were also killed.

The attack was the deadliest for the United Nations in Afghanistan since 11 people were killed in 2009, when Taliban suicide bombers invaded a guesthouse in Kabul. It also underscored the latent hostility toward the nine-year foreign presence here, even in a city long considered to be among the safest in Afghanistan — so safe that American troops no longer patrol here in any numbers.

Unable to find Americans on whom to vent their anger, the mob turned instead on the next-best symbol of Western intrusion — the nearby United Nations headquarters. “Some of our colleagues were just hunted down,” said a spokesman for the United Nations Assistance Mission in Afghanistan, Kieran Dwyer, in confirming the attack.