The Taliban struck an army base in eastern Afghanistan's Kunar province, killing at least 21 Afghan soldiers, with six others missing, officials said.
The Sunday attack forced Afghan President Hamid Karzai to postpone his scheduled trip to Sri Lanka, the presidential palace said.
The Afghan Defense Ministry said the soldiers were killed at the outpost in the province's Ghaziabad district near the border with Pakistan, the Wall Street Journal reported. The Taliban claimed responsibility for the assault, which the Defense Ministry said was launched by hundreds of "Afghan and foreign terrorists."
The Taliban told the BBC they had captured the missing soldiers.
The attack came as U.S.-led international forces are winding down their combat operations to leave the country by the end of this year.
The New York Times said international and U.S. forces lately have mostly stopped accompanying Afghan forces on combat missions, raising concerns about whether Afghan units can fight insurgents by themselves.
The Times quoted Kunar province Gov. Shuja al-Mulk Jalala as saying it appeared infiltrators had let the Taliban insurgents into the base, allowing them kill most of the victims as they slept.
Local Taliban leaders denied the presence of infiltrators at the base, the Times said.
"When U.S. warplanes were over our heads, we conducted our operations successfully, and now that they no longer fly above us, we conduct our operations still more successfully," said one.
The Defense Ministry said its soldiers fought the insurgents for about 4 hours.
"These ANA soldiers resisted the enemy assault and fought to death against hundreds of both insider and outsider terrorists who assaulted them," it said.
The ministry said a battalion of reinforcements sent to the area was ambushed by insurgents aided by a suicide bomber.
"They were not hurt and reached the area to begin a counterattack to chase the enemy away," the statement said.
Karzai's government recently released 65 detainees from the Bagram prison despite warnings by U.S. military officials that they were insurgents who might rejoin the Taliban after being freed.
Presidential elections are to be held in April to choose a successor to Karzai, who cannot run again.