Afghan troops have recaptured government buildings in a western city which was attacked by the Taliban, officials say.
On Wednesday, the Taliban entered Qala-e-Naw, the first direct assault on a provincial capital since the US began pulling out its last troops.
Air strikes were used and special forces deployed to push the fighters back, Reuters news agency said.
The Taliban have been making gains as the US and allies pull out.
“The enemy suffered heavy casualties and now we are advancing and driving the enemy out,” special forces commander Sayed Nezami said, according to Reuters.
A spokesperson from the Ministry of Interior Affairs said the city had been cleared of Taliban fighters and that it was now fully under the control of Afghan security forces, according to a report by the Khaama Press News Agency.
A news report by Tolo also quoted the provincial governor as saying the Taliban had been “pushed back from several parts of the city”.
The vast majority of remaining foreign forces in Afghanistan have left ahead of an 11 September deadline, leaving the Afghan military completely in charge of national security.
On Wednesday, Taliban fighters had briefly entered Qala-e-Naw, in Badghis province.
Local sources told the BBC the militants gained access to the city’s prison and freed about 400 inmates, including more than 100 of their own fighters. Afghan forces guarding the prison were reported to have surrendered without a fight.
At the time, provincial Governor Hisamudin Shams said the headquarters of the intelligence service had been set on fire.
But he denied reports the city had fallen to the Taliban, and said Afghan troops were defending it. The governor had told Reuters the militants attacked the city from three directions in the morning.
The Taliban have seized dozens of districts in recent weeks and are now thought to control about a third of the country, making new gains on a daily basis. So far provincial capitals have remained under government control.
Under a deal with the Taliban, the US and its Nato allies agreed to withdraw all troops in return for a commitment by the militants that they would prevent extremist groups from operating in areas they control.
But the Taliban did not agree to stop fighting Afghan forces, whose ability to hold off the insurgents is being questioned.
Military officials in Kabul have talked about “tactical retreat” whenever insurgents make gains, but commanders in the battlefield have told the BBC about a lack of ammunition, and delays in sending support.
Fleeing Afghan troops
Neighbouring countries are bracing themselves for a potential influx of refugees if the fighting continues to intensify.
The foreign minister of Iran, which shares a border with Afghanistan, said the US had failed in Afghanistan and its presence had caused major damage to the country. Mohammad Javad Zarif was speaking in Tehran during a meeting between an Afghan delegation and representatives of the Taliban.
President Ashraf Ghani insists that Afghan security forces are fully capable of keeping insurgents at bay, but more than 1,000 Afghan troops fled over the border to Tajikistan in recent days, and there have also been reports of more soldiers seeking refuge in Pakistan and Uzbekistan to escape the fighting.
Earlier in the week, Taliban spokesman Suhail Shaheen told the BBC that the group was not responsible for the recent increase in violence. He insisted that many districts had fallen to the Taliban through mediation after Afghan soldiers refused to fight.
For the people of Afghanistan, it is a worrying time. The Taliban, who have been accused of various human rights and cultural abuses, support punishments such as public executions of convicted murderers – as well as banning television, music and cinema, and disapproving of girls over 10 going to school.
US-led forces ousted the Taliban from power in Afghanistan in 2001. The group had been harbouring Osama Bin Laden and other al-Qaeda figures linked to the 9/11 attacks in the US that triggered the invasion. However, it has gradually been regaining territory in recent years.
The Taliban entered direct talks with the US in 2018, and President Joe Biden has said the American pull-out is justified as US forces have made sure Afghanistan cannot become a base for foreign jihadists to plot against the West again.
Many observers question that claim.
Twenty years of conflict in Afghanistan – what happened when?
From 9/11, to intense fighting on the ground, and now full withdrawal of US-led forces, here’s what happened.
Al-Qaeda, led by Osama Bin Laden in Afghanistan, carries out the largest terror attack ever conducted on US soil.
Four commercial airliners are hijacked. Two are flown into the World Trade Centre in New York, which collapses. One hits the Pentagon building in Washington, and one crashes into a field in Pennsylvania. Nearly 3,000 people are killed.
First air strikes
A US-led coalition bombs Taliban and al-Qaeda facilities in Afghanistan. Targets include Kabul, Kandahar and Jalalabad.
The Taliban, who took power after a decade-long Soviet occupation was followed by civil war, refuse to hand over Bin Laden. Their air defences and small fleet of fighter aircraft are destroyed.
Fall of Kabul
The Northern Alliance, a group of anti-Taliban rebels backed by coalition forces, enters Kabul as the Taliban flee the city.
By the 13 November 2001, all Taliban have either fled or been neutralised. Other cities quickly fall.
After protracted negotiations at a “loya jirga” or grand assembly, the new Afghan constitution is signed into law. The constitution paves the way for presidential elections in October 2004.
Hamid Karzai becomes president
Hamid Karzai, the leader of the Popalzai Durrani tribe, becomes the first president under the new constitution. He serves two five-year terms as president.
UK troops deployed to Helmand
British troops arrive in Helmand province, a Taliban stronghold in the south of the country.
Their initial mission is to support reconstruction projects, but they are quickly drawn into combat operations. More than 450 British troops lose their lives in Afghanistan over the course of the conflict.
US President Barack Obama approves a major increase in the number of troops sent to Afghanistan. At their peak, they number about 140,000.
The so-called “surge” is modelled on US strategy in Iraq where US forces focussed on protecting the civilian population as well as killing insurgent fighters.
Osama Bin Laden killed
The leader of al-Qaeda is killed in an assault by US Navy Seals on a compound in Abbottabad in Pakistan. Bin Laden’s body is removed and buried at sea. The operation ends a 10-year hunt led by the CIA. The confirmation that Bin Laden had been living on Pakistani soil fuels accusations in the US that Pakistan is an unreliable ally in the war on terror.
Death of Mullah Omar
The founder of the Taliban, Mullah Mohammed Omar, dies. His death is kept secret for more than two years.
According to Afghan intelligence, Mullah Omar dies of health problems at a hospital in the Pakistani city of Karachi. Pakistan denies that he was in the country.
Nato ends combat operations
At a ceremony in Kabul, Nato ends its combat operations in Afghanistan. With the surge now over, the US withdraws thousands of troops. Most of those who remain focus on training and supporting the Afghan security forces.
The Taliban launch a series of suicide attacks, car bombings and other assaults. The parliament building in Kabul, and the city of Kunduz are attacked. Islamic State militants begin operations in Afghanistan.
Death toll announcement
Afghan President Ashraf Ghani says more than 45,000 members of his country’s security forces have been killed since he became leader in 2014. The figure is far higher than previously thought.
US signs deal with Taliban
The US and the Taliban sign an “agreement for bringing peace” to Afghanistan, in Doha, Qatar. The US and Nato allies agree to withdraw all troops within 14 months if the militants uphold the deal.
Date for final withdrawal
US forces are scheduled to withdraw from Afghanistan by 11 September 2021, exactly 20 years since 9/11. There are strong indications that the withdrawal may be complete before the official deadline.