Also on Thursday, Taliban gunmen opened fire on a compound in eastern Pakistan housing police trainees, killing nine of them, officials said.
The militants who staged the cross-border attack appeared to be targeting an anti-Taliban militia in Kitkot village near Pakistan's Bajur tribal area, said Tariq Khan, a local government official. They came from Afghanistan's Kunar province and took hundreds of villagers hostage, including anti-Taliban militiamen, he said.
Hundreds of Pakistani soldiers surrounded the village and killed 12 militants, Khan added. Two militiamen were also killed in the fighting.
Soldiers have retrieved scores of villagers, but dozens more are still held by the militants or trapped in their homes by the fighting, said Khan and two security officials, who spoke on condition of anonymity because they were not authorized to talk to the media.
The army called in gunship helicopters for support but have not used them for fear of civilian casualties, Khan said.
The information could not be independently verified because the area is largely off-limits to reporters.
The police targeted in Lahore were training to be prison guards, said Habibur Rehman, chief of police in Punjab province, whose capital is Lahore.
Pakistani Taliban spokesman Ahsanullah Ahsan claimed responsibility for the attack, saying it was revenge for police torture of their fighters in prison. He spoke to the Associated Press by telephone from an undisclosed location.
In addition to the police who were killed, eight were wounded, said Salman Saddiq, a government official.
One of the wounded, Shafqat Imran, said that eight to 10 attackers, who had their faces hidden behind hoods, stormed into the compound and started shooting randomly. They shouted "God is great," then shot the policemen one by one, said Imran, speaking from a hospital bed.
The police who were attacked were recruited from northwest Khyber Pakhtunkhwa province, a one-time base for the Taliban, and were brought to Lahore for training, Rehman said.
The Pakistani military launched a massive offensive against the Taliban in Khyber Pakhtunkhwa's Swat Valley in 2009, and many militants were captured and imprisoned.
The leader of the Taliban in Swat, Maulana Fazlullah, escaped and is believed to be based in eastern Afghanistan, where he has been sending fighters back across the border to attack northwest Pakistan.
The Pakistani Taliban has killed thousands of soldiers, police, and civilians over the last few years, declaring war on the government to get it to break ties with the United States and establish Islamic law throughout the country.