The fighters on Sunday were in control of Helmand province's Deshu district headquarters, 700km south of the capital Kabul, throughout the exchange before being forced out, officials said.
"A group of Taliban attacked the district headquarters of Deshu Sunday morning and in the exchange of fire nine Afghan soldiers were killed and three were injured," district commissioner Haji Muhammad Rahim said.
"Taliban were in control of the district headquarters for two hours and then we managed to force them out."
There was no word on the fighters' casualties. A Western security source in Kandahar linked the attack to an ongoing counter-narcotics drive in Helmand province and said security was deteriorating there.
"There is a lot of unrest in Helmand province at the moment because of drugs eradication," he said.
Violence has surged in recent weeks after the bitterest winter in a decade reduced attacks to a minimum, with a rise in Taliban-related violence in southern, southeastern and eastern Afghanistan.
More than 18,000 US-led forces and Afghanistan's newly trained national army and national police are fighting remnants of the former Taliban government, which was toppled from power by a US-led force in late 2001.
Opium poppy cultivation has soared since the ousting of the Taliban, and Afghanistan now produces 90% of the world's heroin.