Pakistan army, paramilitary troops and the air force launched a joint operation "to evict terrorists' stronghold of Walidad" in the northwest district of Mohmand on Saturday, the military said on Sunday.
"Ground operation was preceded with precise strikes by Pakistan Air Force aircraft on terrorists' bunkers and positions," it said.
"After an intensive fight, troops were able to secure Walidad Top and surrounding areas of the mountain and managed to kill 25 terrorists, while remaining fled across the border," it said.
Four soldiers were killed and eight wounded.
Local officials earlier said three soldiers were killed and at least 13 wounded when dozens of Taliban stormed a check post in the region near the Afghan border.
The pre-dawn attack was mounted in Baizai village of Mohmand facing the eastern Afghan province of Kunar, local administration chief Maqsood Hussain told AFP.
"The militants, believed to be more than 50 and armed with light and heavy weapons, launched an attack on Walidad Kor post, triggering a gunfight that lasted about an hour," he said.
Three soldiers of the paramilitary Frontier Corps were killed and at least 13 wounded, he said adding that four militants were killed and an unspecified number wounded.
The military statement said "troops are consolidating their positions in the area and search operation for remnants is in progress."
Mohmand is one of seven districts in Pakistan's semi-autonomous tribal belt where Taliban and Al-Qaeda-linked militants frequently launch attacks targeting police, government and security officials.
Washington has called the tribal zone the most dangerous place on Earth and the global headquarters of Al-Qaeda, where Taliban and other Al-Qaeda-linked networks have carved out strongholds.
Since US Navy SEALs killed Osama bin Laden in Pakistan last month, American officials have been increasing pressure on Islamabad to launch an offensive in the North Waziristan district to destroy militant sanctuaries.