A group of some 60 militants carried out the attack, entering from Afghanistan and firing on a vehicle carrying security forces in the Bajur tribal region, said Shah Nasim, a senior government administrator there. He initially said the militants had attacked an army post.
Another soldier and a civilian cook were injured in the attack, Nasim said, which ended with the assailants escaping to Afghanistan's Kunar province, some of them injured from the exchange of fire.
The foreign ministry condemned the attack, saying "a strong protest has been lodged with the Afghan side in Islamabad and Kabul."
Pakistan's army largely has cleared the Bajur tribal region of militants but its posts often come under cross-border attacks. In June, militants killed 20 soldiers in three attacks. Pakistani troops killed some 50 attackers in retaliatory actions.
Pakistan and Afghanistan share a 2,250-kilometer (1,400-mile) border and militants from both sides routinely launched attacks from one side before fleeing back to the other. Pakistan has asked Afghanistan's government to take action against the Pakistani militants who escaped a recent military offensive in the Swat Valley and elsewhere for safe havens in eastern Afghanistan.
The military says so far it has killed more than 400 terrorists, though activists and locals say civilians also have been killed.
Since the start of the operation, more than 800,000 people have fled the region, raising fears of a humanitarian crisis.