Hangu district, which has a history of violence between minority Shia and majority Sunni sects, is close to tribal areas bordering Afghanistan where pro-Taliban fighters are active.
"Hundreds of Taliban attacked the convoy and did not allow security forces to retrieve the dead bodies of the soldiers for several hours," Fazan Khan, a local official, said.
Security forces responded by attacking Taliban positions in the mountainous region using helicopter gunships and artillery fire.
"We have reports three fighters were killed and 10 wounded in retaliatory fire," a security official said.
Meanwhile, the fate of a group of hostages seized in the area was unclear after a deadline set by their captors passed without their conditions being met.
Maulvi Umar, the spokesman for the Pakistani Taliban, said on Friday that 29 people, most of them security forces, had been captured and they would be killed if the government did not release a number of prisoners on Saturday.
Haji Khan Afzal, a Hangu district official said only 16 or 17 people were being held.
Saturday's attack was the latest incident in a bloody week in the country.
A suicide attack killed at least 19 people near a protest marking the anniversary of a government-backed raid on the Red Mosque in Islamabad six days ago.
Although there was no immediate claim of responsibility, officials said they were examining a range of possible culprits, including the mosque's former students and Taliban fighters based near the Afghan border.
That bombing was followed the next day by a string of six blasts in the southern port city of Karachi, which killed one person and injured 37.
Pakistani forces launched an operation two weeks ago in the northwestern city of Peshawar.