The army said it retaliated and killed two or three attackers in the incident that occurred in Pakistan's Bajaur district.
Militant fire from across the border in Afghanistan has killed two Pakistani soldiers, the army said, in the second such attack since the Taliban took over Kabul two weeks ago.
The army said it retaliated and killed two or three attackers in Pakistan's Bajaur district on Sunday.
Bajaur is one of several lawless tribal regions along the Afghan border which have long sheltered militants, including a militant umbrella organisation called Tehrik-e-Taliban Pakistan (TTP).
The army did not say which group was behind the attack, but has long held that TTP leaders and fighters are sheltering in Afghanistan after fleeing the tribal districts during military operations targeting militants.
"As per intelligence reports, due to fire of Pakistan army troops, 2-3 terrorists got killed and 3-4 terrorists got injured," the military said in a statement.
"We expected that the way things were unfolding in Afghanistan, the violence can spill over in Pakistan," Pakistan army spokesman Major General Babar Iftikhar told a news conference on Friday.
The incident is the second of its kind reported since the Taliban took over Kabul on August 15.
A soldier was killed in Pakistan's Lower Dir district after taking fire from a militant across the border, an ISPR news release said on Thursday night.