"Anti-government elements" in Afghanistan attacked the main UN compound in the capital of the western province of Herat on Friday and at least one security guard was killed, the UN Assistance Mission in Afghanistan (UNAMA) said.
The attack, involving rocket-propelled grenades and gunfire, happened hours after Taliban fighters penetrated deep into Herat city, and there were heavy clashes with Afghan security forces near the UNAMA provincial headquarters, officials said.
It also came as US-led foreign forces near a complete withdrawal of troops and Afghan security forces struggled to hold back Taliban fighters in three major provincial capitals, reports Reuters.
In a statement following the attack, the United Nations said it was urgently seeking to establish a full picture of the assault and was in contact with the relevant parties.
It was not immediately clear who attacked the compound, but a Western security official told Reuters all diplomatic compounds in the city were put on high alert.
"The United States strongly condemns the attack on the United Nations compound in Herat," White House national security adviser Jake Sullivan said in a statement, reiterating a US call for reduction in violence in Afghanistan.
UNAMA said the attack was against the entrances of the compound that were clearly marked as a UN facility.
“This attack against the United Nations is deplorable and we condemn it in the strongest terms,” said Deborah Lyons, the UN Secretary-General’s Special Representative for Afghanistan.
UNAMA said no UN personnel were hurt.
The Taliban put the incident down to possible crossfire.
"It is possible that guards could have sustained harm in crossfire due to close proximity of the office to the fighting," the insurgents' spokesman, Zabihullah Mujahid, said on Twitter.
He added that Taliban fighters had "arrived at the scene" and that the compound was "not under any threat".
The Taliban have already captured swaths of the province of Herat, which borders Iran, before entering the capital.
A high-ranking foreign security official told Reuters Iranian border guards were on high alert as they fear many could flee across the border in coming days.
Foreign staff in all embassy offices in the city had been advised to observe a strict lockdown, the official added.
Herat city is the second provincial capital the Taliban have entered in the last 24 hours. Insurgents entered Lashkargah, the capital of the southern province of Helmand, a day earlier, and clashes were underway there. Civilians rushed to evacuate the city.
The Taliban, seeking to reimpose strict Islamic law after their 2001 ouster, have made swift territorial gains over the last two months but have not yet captured any provincial capitals.
"Since Thursday morning, the Taliban have launched attacks from several directions on Lashkargah city," a government official told Reuters on the condition of anonymity.
The official said government forces had thus far held back the Taliban with the help of airstrikes, but operations were hampered by the presence of civilians in the area.
"Hundreds of families have left the area," Hafiz Ahmad, a resident of Lashkargah, told Reuters.
He said those unable to move had locked themselves in their homes, and the city wore a deserted look as gun and artillery fire reverberated through neighbourhoods.
A UN report this week said civilian casualties had been surging in recent weeks, with as many killed in May and June as in the previous four months. The report did not cover casualties in July, when fighting intensified further.
Earlier on Friday, UNAMA expressed deep concern at the escalating violence in and around the southern city of Kandahar and warned of grave consequences for civilians.
It said more than 230 civilians had been wounded, and there were reports that scores had been killed, over the last two weeks.
A senior government official in Kandahar told Reuters that fighting between the Taliban and government forces had reached the central parts of the city, and residents feared insurgents could take over.
Airstrikes targeted Taliban positions to ensure security forces' supply lines remained open in the besieged city, known as the birthplace of the Taliban.
The United States' top regional military commander has said the US Air Force had increased airstrikes to support Afghan forces - but declined to say whether this would continue after their military mission ends on Aug 31.