Government forces in Afghanistan have recaptured buildings that were attacked and taken over by the Taliban, officials said.
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 reported.
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.
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 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 briefly entered Qala-e-Naw, in Badghis province.
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.
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.