The fighting erupted on Thursday night after rebels killed a soldier at a security post in Datakhel village, near Miranshah, the main town in the restive North Waziristan tribal zone and the scene of fierce clashes earlier this month.
"Up to 20 militants were killed when security forces responded to the rocket and small arms attack on the checkpost, in which one solider was killed," top military spokesman Major General Shaukat Sultan told AFP.
"The militants while running away left behind a few weapons also."
Pakistan, a key ally in the US-led "war on terror", has deployed 80,000 troops along the border since 2003 to flush out al-Qaeda and Taliban rebels who sneaked across from Afghanistan after the ouster of the Taliban regime in late 2001.
Sultan had no details but local and army officials said a number of foreign rebels were among those who died in Friday's fighting, which started at around 2:45 am and lasted for some two hours.
"Around 20 militants, including some foreigners, were killed when security forces struck their hideout with helicopter gunships and artillery after the attack on a security post which killed one soldier and injured two others," a military official told AFP on condition of anonymity.
The fighting lasted two hours
A local official said seven of the dead were foreign.
The official added that two injured attackers were arrested, along with eight other people with suspected links to insurgents.
Tribal fighters linked to the Taliban briefly took control of Miranshah in the first week of March - during a visit to Islamabad by US President George Bush - in revenge for an earlier raid on a suspected al-Qaeda training camp.
Fierce clashes erupted when Pakistani forces tried to retake the the town, leaving around 170 rebels and five soldiers dead and forcing thousands of civilians to flee the area.
Musharraf late on Thursday promised a crackdown on foreign fighters, amidst tensions between Afghanistan and Pakistan over allegations that Islamabad was failing to tackle Islamic rebels launching cross-border raids from its territory.
"We will never tolerate foreign terrorists and extremists" hiding in the tribal region, Musharraf told a rally in the eastern city of Lahore.
"These foreign militants are indulging in acts of terrorism not only in Pakistan but elsewhere in the world also," he said. "I warn them to leave Pakistan, failing which we will eliminate them."
Military and security sources have said that so-called Pakistani Taliban are in control of parts of the tribal zones, where they have set up a virtual state within a state governed by a strict interpretation of Sharia law.
"These foreign militants are indulging in acts of terrorism not only in Pakistan but elsewhere in the world also"
But Pakistani officials say reports that the Taliban have taken over the local administration are "totally wrong and baseless".
Pakistani authorities last week also ordered thousands of Afghans living in these tribal areas to go back to their native country.
Meanwhile Pakistan on Thursday lodged a "strong protest" with Afghanistan over the killing by Afghan troops this week of 16 people who it says were civilians heading to a festival.
Kabul says it is investigating the incident, which happened across the border from Pakistan's southwestern province of Baluchistan, but an Afghan army officer has said the dead men were Taliban rebels.