Four protesters also died in the violence in Mazar-i-Sharif. Other demonstrations, which were peaceful, were held in Kabul and Herat, fueling resentment against the West at a critical moment in the Afghan war.
Afghan authorities suspect insurgents melded into the mob at the compound. They announced the arrest of more than 20 people, including a militant they suspect was the ringleader of the assault in Mazar-i-Sharif, the provincial capital of Balkh province.
The suspect was an insurgent from Kapisa province, a hotbed of militancy about 250 miles southeast of the city, said Rawof Taj, deputy provincial police chief.
The topic of Quran burning stirred outrage among millions of Muslims and others worldwide after the Rev. Terry Jones' small church, Dove Outreach Center, threatened to destroy a copy of the holy book last year. The pastor backed down, but the church in Gainesville, Fla., went through with the burning last month.
Late Friday, Dan McNorton, a spokesman for the United Nations Assistance Mission in Afghanistan in Kabul, revised the death toll to seven -- four foreign security guards and three other foreigners.
The guards were from Nepal, according to Gen. Daud Daud, commander of Afghan National Police in several northern provinces. The other three killed were from Sweden, Norway and Romania, officials said.
Munir Ahmad Farhad, a spokesman in Balkh province, said the protest began peacefully when several hundred demonstrators gathered outside the UN mission's compound, choosing an obvious symbol of the international community's involvement in Afghanistan to denounce the Quran's desecration. It turned violent when some protesters seized the guards' weapons and started shooting, then the crowds stormed the building and set fires that sent plumes of black smoke into the air, he said.
One protester, Ahmad Gul, a 32-year-old teacher in the city, gave a different account. He said the protesters disarmed three guards to prevent any violence from breaking out. Associated Press video showed protesters banging AK-47 rifles on the curb, breaking them into pieces. He said the protesters were killed and wounded by Afghan security forces.
The UN Security Council scheduled an emergency meeting on the deadly attack, which drew condemnations from around the world.
President Barack Obama condemned the attack and underscored the importance of the UN's work in Afghanistan. At the U.S. State Department, spokesman Mark Toner said the burning of a Quran in Florida was contrary to Americans' respect for Islam and religious tolerance.
The church's website stated that after a five-hour trial on March 20, the Quran "was found guilty and a copy was burned inside the building." A picture on the website shows a book in flames in a small portable fire pit.
In a statement, Jones did not comment on whether the church's act had led to the deaths. Instead he said it was time to "hold Islam accountable."