Pro-Taleban militants have released more than 200 Pakistani soldiers who were captured near the Afghan border in August, military officials have said.
The soldiers were handed over to tribal elders in South Waziristan, the lawless region where they were being held.
The Pakistani authorities released 28 militants in exchange, reports say.
The soldiers were captured on 30 August, without a shot being fired, as their convoy was taking supplies to remote army camps.
"The soldiers have returned to their camp in South Waziristan," Maj-Gen Waheed Arshad said.
The kidnappers, who are loyal to Taleban commander Baitullah Mehsud, were demanding the release of jailed comrades in return for the soldiers' freedom.
One of the negotiators who secured the soldiers' release told the BBC that the authorities had agreed to release nearly 30 militants - some of them suspected suicide bombers.
A military spokesman only confirmed that the local authorities had released some detained tribesmen
Three of the kidnapped soldiers were killed by militants in September as a warning to the government not to launch a rescue operation.
The BBC's Syed Shoaib Hasan, who recently travelled to the militants' camp to meet the captured men, says the capture of the soldiers was a major blow to the Pakistani army which is having to deal with lowering morale among its troops.
Pakistan has tens of thousands of troops in the area, struggling to quell unrest in a region where tribesmen do not recognise the Islamabad government.
The US says the area has become a safe haven for al-Qaeda since the 11 September 2001 attacks on New York and Washington.