The bloody attack showed the threat still posed by the Pakistani Taliban, despite army offensives. Increasingly, the militants have used sanctuaries in eastern Afghanistan to attack border areas in Pakistan's northwest.
Pakistan has criticized NATO and Afghan forces for not doing enough to stop the attacks, but it has received little sympathy. The Afghan government and its allies have long faulted Pakistan for failing to target AfghanTaliban militants and their allies who use Pakistani territory to launch attacks in Afghanistan.
The Pakistani and Afghan Taliban are allies, but the former has focused on fighting the Pakistani government, while the latter has concentrated on attacking foreign and local forces in Afghanistan.
The Pakistani Taliban said in the video that they killed 18 soldiers, but 17 heads were displayed on a bloody white sheet on the ground outside. Several militants whose faces were covered were standing around the heads, holding weapons they said were captured from the soldiers.
The Associated Press obtained the video by email Wednesday from Pakistani Taliban spokesman Ahsanullah Ahsan.
The beginning of the video contains a voice recording by Pakistani Taliban chief Hakimullah Mehsud in which he says the militants will continue to battle the army until Pakistan's government stops supporting the U.S. and enforces Islamic law throughout the country. It was unclear when the message was recorded.
The Pakistani military said previously that 13 troops were killed in Sunday night's cross-border raid into the country's northwest Upper Dir region, and seven of them were beheaded. Four others were reported missing at the time. The military did not immediately respond to request for comment on the video.
The Pakistani Taliban and their allies have staged scores of bombings and other attacks against security forces and civilians in the country, killing thousands.
The latest attack came during serious political instability in the country.
The Supreme Court forced former Prime Minister Yousuf Raza Gilani to step down last week after convicting him of contempt for failing to reopen an old corruption case against the president.
On Wednesday, Supreme Court Chief Justice Iftikhar Chaudhry said in a court session that he expects the new prime minister, Raja Pervaiz Ashraf, to comply with the court's order to reopen the case, a sign that the legal crisis will continue to shake Pakistani politics, said Waseem Sajjad, a lawyer involved in the case.
Prime Minister Ashraf has refused to say whether he would comply with such a court order, and analysts said that was unlikely.
Critics say that by pressing the case against the president, the court is taking on a political role in a country where elected governments have been routinely squeezed by the military, often in cooperation with the court.
Court backers say activist judges limit corruption and government misuse of power. The court has also been investigating alleged human rights abuses by the military.