The security forces were carrying out search operation in border areas of Salarzai in Bajaur district on the Afghan border when militants launched an attack, leading to clash.
A security official said the troops effectively responded to the attack and repulsed the militants.
"Seven attackers were killed in the clash while two soldiers and a captain embraced martyrdom in the fight," he said.
Two more soldiers were injured in the gun-battle and shifted to hospital for treatment.
More From This Section
Once it was considered as stronghold of al-Qaeda and Taliban but forces have cleared it vast areas.
However, militants often enter from Afghanistan through porous border to attack the forces and pro-government tribesmen.
Pakistani troops have been engaged in a full-scale offensive against Taliban and other militants in North Waziristan and Khyber tribal districts since last year.