There were no casualties among UN workers, Delawar Shah Delawar, deputy police chief of Herat province, told AFP after the raid, which was claimed by the Taliban.
"One of the suicide attackers drove his explosives-packed vehicle into the rear gate of the compound. The two other attackers tried to enter the building after the blast but they were killed by guards and policemen," he said.
"At this stage we are searching the compound to make sure there are no attackers hiding inside the building," he said, adding:
"The attack did not cause any casualties to security forces or UN workers."
UN officials in Kabul and Herat confirmed the attack and that there were no deaths or injuries among UN staff, who had taken refuge in a safe bunker.
The United Nations has been seen as a specific target of the Taliban since last October, when a Kabul guesthouse was attacked and 12 people, including six UN employees, were killed.
The latest attack began at 12:30 pm, an AFP reporter on the scene said, adding that explosions and small arms fire was heard from inside the compound, which is about eight kilometres from Herat city centre.
The remains of the vehicle lay by the destroyed gate, with body parts — possibly those of the attackers — strewn around it, the reporter said.