Troops lifted a cordon around the scene of the worst fighting since the launch 12 days ago of the biggest ever Pakistani operation against fighters hiding around the remote South Waziristan area, near the Afghan frontier.
US forces are hunting fighters on the other side of the mountainous border.
The 12 men released on Sunday were among 14 soldiers and officials captured by alleged al-Qaida-linked groups and tribal allies at the start of a clash in which more than 100 people have been killed in South Waziristan.
After cordoning off the area with 5000 troops and losing about 50 soldiers in the offensive, the military said on Saturday it had smashed a den of fighters believed to include Uzbeks, Chechens, Arabs, Afghans and local Pashtun clansmen.
The remaining two held captive would be released later on Sunday, said a tribal elder involved in the negotiations.
As talks among tribal elders ended, troops manning the 60km cordon began pulling back to a nearby base camp.
"The army cordon is to be withdrawn today. We have almost achieved our set targets," Mahmud Shah, the region's security chief said. "The army had demolished 83 houses and almost all the hideouts of militants in this area."
Tension is high after the reported execution of eight Pakistan soldiers who had been taken hostage by the fighters during an ambush on an army convoy on Tuesday.
Eight Pakistani soldiers were
A senior al-Qaida linked leader, Tahir Yuldashev, was badly wounded but escaped, military officials said on Sunday.
Yuldashev, leader of the Islamic Movement of Uzbekistan, was accused of a series of bomb blasts in the Uzbek capital, Tashkent, in 1999.
"He is in our tribal area," said Shah. "We are hunting him."
The fighting began when paramilitary forces searching for al-Qaida and other fighters ran into a hail of bullets on 16 March, suggesting tribesmen were helping to protect a "high-value target", perhaps bin Ladin's deputy Ayman al-Zawahri.
The military later dismissed that as "conjecture" but said an Uzbek or Chechen leader might be among the fighters.
Hunt to continue
Many of the fighters are believed to have fled to other parts of Pakistan's barren western frontier. About 50,000 army troops have been deployed in the rugged terrain to hunt them.
"Their hideouts are finished and the army is destroying their houses," Information Minister Shaikh Rashid Ahmad said. "We will continue to hunt Yuldashev."
Pakistani Minister Rashid Ahmad
(L) says troops will stay in area
Troops claimed to have killed around 60 fighters and captured 162, about 100 of them foreigners, in the semi-autonomous tribal region.
More than a dozen civilians are believed dead.
Pakistani troops had held fire in recent days to let a delegation of tribal elders negotiate the release of the 14 men.
Ahmad said troops would stay in the area to hunt al-Qaida and other fighters, creating a new camp not far from Wana, scene of some of bloodiest fighting.
Pakistan's tribal belt has been a magnet for Muslim fighters since the 1980s when a stream of volunteers turned up from around the world, with the backing of Pakistan and the United States, to help oust occupying Soviet forces in Afghanistan.