Taliban insurgents targeted an Afghan army corps at their camp in southern Helmand province, killing at least 23, officials said on Saturday.
Omar Zwak, the spokesman for the provincial governor, said 16 other troops were wounded in the 17-hour battle that ended on Friday night in Washer district.
Qari Yusouf Ahmadi, a Taliban spokesman, in a statement, said the insurgent group was responsible for the attack, which came even as Taliban negotiators met for talks with a US peace envoy in the Middle Eastern state of Qatar.
He said Taliban fighters engaged both Afghan and foreign forces inside the camp and killed "scores".
Zwak said US advisers were present in the base, but in a separate area.
"The foreign forces present at the base were all safe as the Taliban could not reach that part of the compound," he said.
Zwak said the attack began when a suicide bomber detonated his explosives at Shorab camp. He said three other suicide bombers also blew themselves up as gunmen followed behind them. Zwak said 16 Taliban gunmen were killed during 17 hours of fighting.
In recent years, the Taliban and the militant Islamic State group have carried out near-daily attacks in Afghanistan, mainly targeting the government and its security forces.
The Taliban control several district centres in Helmand, which is a major source of the world's illegal opium supply.
Ghafor Ahmad Jawed, the spokesman for the Afghan Defense Ministry, confirmed the death toll at 23 and said a clearing operation ended on Friday night.
Camp Shorab was previously a British air base known as Camp Bastion.