Militants crossed into Pakistan from Afghanistan and killed 13 Pakistani troops, beheading seven of them, the Pakistani military charged, and the country's outraged new prime minister said he would protest to the Afghan president.
The border skirmish is a new sign of tensions between the uneasy neighbours.
Pakistan has complained that militants use parts of Afghanistan for sanctuary to stage attacks inside Pakistan.
That claim helps Islamabad counter frequent US and Nato complaints that militants behind much of the violence in Afghanistan come from Pakistan.
Pakistani military officials said militants from Afghanistan crossed in the north western Pakistan's Upper Dir region on Sunday night and clashed with Pakistan forces on a patrol.
The military said six Pakistani troops were killed outright. Seven who went missing were beheaded, while four of the missing have not been found.
The military's statement also said Pakistani troops killed 14 of the militants. The military's account could not be independently verified.
Reflecting the particularly gruesome nature of the attack, newly chosen prime minister Raja Pervaiz Ashraf said he would complain directly to Afghan president Hamid Karzai.
“We have strongly protested and I will, too, God willing, talk about this to Karzai,” said Mr Ashraf, speaking in Karachi.
The Pakistani Taliban said their fighters carried out the raid, but the statement did not say whether the attackers had crossed over from Afghanistan. It said Pakistani claims of militant casualties were false.
Both sides often release false or partial information about such events, which usually happen in areas inaccessible to the media.
The border region between Afghanistan and Pakistan is a hotbed of militant insurgency largely removed from the control of either government.