The attack started with a massive blast outside the United Nations building in the western Afghan city of Herat.
A suicide bomber destroyed the gates of the United Nations Assistance Mission in Afghanistan's (UNAMA) compound, allowing several other insurgents dressed in police uniforms and women's burqas to enter the building.
Local officials say the attackers were armed and wore explosives vests.
Zamari Bashari, a spokesman for the Afghan Interior Ministry, told RFE/RL the raid involved at least three insurgent.
"One of them blew himself up inside a car, right outside the gates. The other two tried to enter the building, but by then our police forces had already started operations."
The total number of assailants, however, remains unclear.
Both UN and local government officials said the raid was over, and there were no casualties among security forces or UN staff, who had taken refuge in a bunker.
Bashari said all the assailants were killed. He also confirmed that there were no casualties among the UNAMA employees but said three members of the security squad were injured.
The Taliban claimed responsibility for the attack.
Attacks are relatively rare in Herat, a commercial hub and the largest city in the country's west. But in recent months the insurgents have stepped up attacks beyond their strongholds in the south and east of the country, despite the presence of around 150,000 foreign troops.
Casualties from the war in Afghanistan are at their highest since U.S.-backed Afghan troops ousted the Taliban in 2001.
In June, the United Nations announced plans to downsize its international staff in Afghanistan for security reasons.
Militants attacked a UN guesthouse in Kabul last year, killing 12 people including six UN employees and prompting the organization to evacuate hundreds of foreign workers.
RFE/RL's Radio Free Afghanistan contributed to this report