The battle for the Nerkh district, which is in Wardak province about 40 km (25 miles) from Kabul, took place on Wednesday, just before the start of a three-day ceasefire at midnight.
Taliban fighters killed or captured government soldiers on Tuesday and forced others to retreat into central Nerkh.
“The security and defense forces carried out a tactical retreat from the Nerkh district police headquarters,” Interior Ministry spokesman Tareq Arian told AFP news agency.
Government forces are fighting escalating Taliban attacks as US troops withdraw after 20 years of fighting in the country.
Wardak Mayor Zarifa Ghafari said if the district was not taken quickly, fighting would reach the gates of Kabul within days.
The Defense Ministry said on Wednesday that special forces had been deployed to the area to retake the district after troops carried out a “tactical retreat” on Tuesday.
“Commando reinforcements are on the way,” said Defense Ministry spokesman Fawad Aman.
A senior government official said they aimed to regain control ahead of a three-day ceasefire announced by the Taliban for the Muslim religious holiday of Eid, which begins Thursday.
“We will have to do it today because after the ceasefire it will give the Taliban enough time to dig and complicate operations and increase our losses,” the official said, speaking to the news agency. Reuters on condition of anonymity.
The government carried out airstrikes at the start of the operation, the defense ministry said.
The Taliban have maintained a strong presence in Wardak and neighboring Logar province to the south over the years.
Afghan officials say the Taliban have used the provinces as launching pads for light-hearted attacks and suicide bombings in Kabul.
The Taliban launched a months-long campaign to expand its influence across the country as the United States began withdrawing troops from May 1 and closed some bases in accordance with a peace deal signed with the Taliban. last year.
Afghan officials say that since Washington last month announced its intention to withdraw all US troops by 9/11, the Taliban have stepped up their attacks.