Afghan security forces mounted an operation to recapture a Taliban-held district outside the capital Kabul on Wednesday just before the start of a three-day ceasefire at midnight, a local official said.
Taliban insurgents had killed or captured some government soldiers and forced others to retreat after storming the district centre, which lies in Wardak province less than an hour's drive from Kabul.
Government forces have been struggling against stepped-up attacks by the insurgents as US troops withdraw after two decades of fighting in the country.
Wardak mayor Zarifa Ghafari said that if the district was not taken soon, fighting would reach the gates of Kabul in a few days.
The defence ministry said on Wednesday special forces have been deployed in the area to retake the district after troops made a "tactical retreat" on Tuesday.
A senior government official said they aimed to regain control before a three-day ceasefire announced by the Taliban for the Muslim religious holiday of Eid, which starts on Thursday.
"We will have to do it today because after the ceasefire, it will give the Taliban enough time to dig in and will complicate the operations and increase our casualties," the official said, speaking on condition of anonymity.
The government carried out air strikes at the start of the operation, the defence ministry said.
The insurgents have maintained a strong presence in Wardak and nearby Logar province to the south over the years. Afghan officials say the Taliban have used the provinces as launchpads for hit-and-run attacks and suicide bombings on Kabul.
The Taliban has staged a months-long campaign to expand its influence across the country as the United States has begun withdrawing troops from May 1 and closed some bases in keeping with a peace deal it signed with the Taliban last year.
Afghan officials say since Washington announced plans last month to pull out all US troops by Sept. 11, the Taliban have stepped up attacks.
Critics of the decision to withdraw say the Islamist militants will try to sweep back into power.
US-led forces ousted the Taliban from power in late 2001 for sheltering the al-Qaeda militants involved in the September 11 attacks on the United States.