An Afghan police guard was killed Friday when a United Nations compound came under attack in Herat, officials said, as fighting raged between government forces and the Taliban on the outskirts of the western city.

Violence has surged across the country since early May, when the Taliban launched a sweeping offensive as the US-led foreign forces began a final withdrawal that is now almost complete.

The militants have seized scores of districts across the country, including in Herat province, where the group has also captured two border crossings adjoining Iran and Turkmenistan.

On Friday, the Taliban clashed with government forces on the outskirts of Herat city, the provincial capital, forcing scores of families to flee, residents said, as the insurgents tightened their noose.

During the fighting, the UN's main compound in Herat came under attack by rocket-propelled grenades and gunfire, a statement issued by the United Nations Assistance Mission in Afghanistan (UNAMA) said.

Afghan forces have been deployed around the western city of Herat in recent days
Afghan forces have been deployed around the western city of Herat in recent days AFP / Hoshang Hashimi

"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.

"The perpetrators of this attack must be identified and brought to account."

UNAMA said the attack was carried out by "anti-government elements".

It said, however, that the area where the compound is located was the scene of heavy fighting between the Taliban and government forces.

The United States said it "strongly condemns" the attack in a statement from White House national security advisor Jake Sullivan.

Violence has surged across the country since early May when the Taliban launched a sweeping offensive as the US-led foreign forces began a final withdrawal
Violence has surged across the country since early May when the Taliban launched a sweeping offensive as the US-led foreign forces began a final withdrawal AFP / Hoshang Hashimi

"The United Nations in Afghanistan is a civilian entity focused on supporting peace efforts, promoting the rights of all Afghans and providing humanitarian and development assistance," Sullivan said in the statement, urging the Afghan government and Taliban to resume peace talks.

UN Secretary-General Antonio Guterres also condemned the attack and repeated the UN's "commitment to support the Government and people of Afghanistan in their efforts to achieve peace and stability".

The militants say they will not target foreign diplomats, but have blatantly violated international protocol before.

When the Islamist hardliners seized control of Kabul in 1996, they entered the UN compound and abducted the country's former leader, Najibullah Ahmadzai, who they brutally tortured and murdered.

Two years later during their hardline regime, Taliban fighters entered the Iranian consulate grounds in Mazar-i-Sharif and killed 10 diplomats and a journalist with the state news agency.

Afghan forces and militiamen of veteran warlord and anti-Taliban commander Ismail Khan have been deployed around the city in recent days
Afghan forces and militiamen of veteran warlord and anti-Taliban commander Ismail Khan have been deployed around the city in recent days AFP / Hoshang Hashimi

The European Union delegation to Kabul blamed the Taliban for the attack on the UN compound in Herat.

"The Taliban have to account for the crime which will be considered an attack against all of us. It is contrary to all assurances given," Ambassador Andreas Von Brandt, head of the EU delegation, tweeted.

For the past two days, the insurgents and government forces have clashed on the outskirts of Herat, Afghanistan's third-largest city with 600,000 inhabitants.

An AFP correspondent there said the Taliban and Afghan forces were also fighting on the road leading to the city airport on Friday, while residents reported clashes in the nearby districts of Injil and Guzara.

"People there are terrified," said Abdul Rab Ansari, who fled to the city from Guzara.

"The fighting is heavy but they have not captured the district of Guzara so far," said Mohammad Allahyar, who also sought shelter in Herat.

Afghan forces and militiamen of veteran warlord and anti-Taliban commander Ismail Khan have been deployed around the city in recent days.

Khan, who previously fought the Soviet occupation forces in the 1980s and then the Taliban during their hardline regime in the 1990s, has vowed to fight the insurgents again to counter their staggering advances in recent months.

Fighting has also raged in the southern provinces of Helmand and Kandahar since Thursday.

In Helmand, the Taliban attacked the provincial capital of Lashkar Gah from several directions on Thursday, local police officer Daud Shah said.

He said the insurgents targeted police checkpoints but were later repelled following air strikes carried out by the Afghan air force.

At least 33 people were wounded in fighting in the past 24 hours across Kandahar province, hospital authorities said.

In a tweet UNAMA expressed concerns around "escalating violence" in and around Kandahar city, citing "credible reports of civilians killed".