Afghan forces backed by Nato air power have repelled an assault by more than 300 militants including foreign fighters on an army base close to the Pakistani border, officials say.
They say that the fighting took place in south-eastern Afghanistan, close to Pakistan's Waziristan region.
The Nato-led force has not commented on the clashes, although local people told the BBC that its aircraft took part.
Scores of militants from the Haqqani network were killed, officials say.
Officials said as many as 60 militants from the Taliban-linked network were killed, but there is no independent confirmation of this.
Five Afghan National Army soldiers were also killed, six wounded and one taken prisoner, they added.
No militant group has commented on the fighting, but defence ministry officials say those orchestrating the attack were Pakistan-based militants. The target of the attack was an army base in the remote border district of Zirkuk in Paktika province, they said.
The restive district lies 12km (7 miles) from the Pakistani town of Miramshah in North Waziristan. The region is a stronghold of the Haqqani network, which also has links to al-Qaeda and has carried out a series of high-profile attacks against foreign troops in Afghanistan.
An army commander in the area told the BBC's Bilal Sarwary in Kabul that Wednesday's fighting was some of "the bloodiest" he had experienced for a long time.
He said the militants used rocket-propelled guns, heavy machine guns and mortars.
Our correspondent says that Zirkuk is a strategic district for the militants and serves as a gateway into Afghanistan.
The group has used the area to transport fighters and weapons from Waziristan into Afghanistan in the past.
Earlier this year, an insurgent attack on an army checkpoint in the eastern province of Kunar killed 21 soldiers. Later it emerged that three soldiers were in collusion with the insurgents and had facilitated the attack.
The BBC's Owen Bennett-Jones says that the high levels of distrust between the governments in Kabul and Islamabad have resulted in the Pakistani Taliban leadership sheltering in Afghanistan while the Afghan Taliban leadership shelters in Pakistan.
The militants have been able to exploit a situation that allows them to move freely across the border between the two countries, while the American, Afghan and Pakistani armies cannot, our correspondent adds.
After the November 2013 death of then Pakistani Taliban leader Hakimullah Mehsud in a drone strike, the organisation selected a jihadi from Swat, Maulana Fazlullah, as his successor. Pakistani media reports say he is currently based in Afghanistan, close to the Pakistani border.
It was the first time since its creation that the Pakistani Taliban was not being led by a member of the Mehsud tribe, and some Mehsuds are unhappy being under Maulana Fazlullah's leadership.
The Pakistani government believes if it can split the Mehsuds, the Taliban and its allies will be considerably weakened.