Three Frontiers Corps personnel were martyred when suspected terrorists opened fire on their team from across the Pak-Afghan border in Mohmand Agency on Friday, an Inter-Services Public Relations (ISPR) statement said.
The troops were targeted when they busy in the construction of a new border post at Shunkrai area of Mohmand tribal region near the border with Afghanistan.
A protection party that was accompanying the troops responded to the attack, killing five suspected terrorists and leaving as many injured, the ISPR said.
The martyred soldiers were identified as Havaldar Muneer Khan, Sepoy Haq Nawaz Khan and Lance Naik Irshad Hussain.
The fleeing terrorists could be seen carrying with them the bodies of killed militants and those injured in retaliatory fire, the ISPR claimed.
The military's media wing alleged that through such attacks, Pakistan is "paying [the] price" of Afghan security forces' lack of "capacity" and ungoverned spaces on Afghan side of the border.
The incident comes less than a fortnight after two Pakistan Army soldiers were martyred when armed militants opened fire on their vehicle in North Waziristan.
It also comes hours after Foreign Affairs Secretary Tehmina Janjua expressed concern over the presence of terrorists in Afghanistan that she said has been detrimental to Pakistan's safety.
She was responding to US Vice President Mike Pence's remarks that the Trump administration has "put Pakistan on notice" with respect to its alleged support for Taliban and other militant organisations.
Pence's statements are the harshest US warning to Pakistan since the beginning of the Afghan war more than 16 years ago and follows several recent statements, indicating US indignation with Islamabad.
Rejecting the US vice president's statements, Janjua said: "The bigger question is how will the US address Pakistan's concerns? Terrorists wanted in Pakistan are hiding away in Afghanistan and the refugee situation is also creating major problems for us."