Gunmen opened fire on an army camp near Islamabad on Monday, killing seven security personnel and wounding five others, the military said.
The encampment was attacked from a bridge over the river Chenab, close to the industrial city of Wazirabad, less than 150 kilometres (100 miles) southeast of the capital.
Just hours before the attack, the Defence Council of Pakistan coalition of right-wing and Islamist groups crossed the bridge on a "long march" from Lahore to Islamabad to protest against the reopening of NATO supply routes to Afghanistan.
Pakistan is battling an Islamist insurgency in its lawless northwest tribal region, but attacks in the area of Monday's incident in the prosperous and generally peaceful province of Punjab are unusual.
"At least seven security personnel including a police official embraced shahadat (martyrdom) and five others were injured due to firing by unknown assailants near Wazirabad," the military said in a statement.
A rescue party had camped by the Chenab to look for the body of a pilot missing in a helicopter crash in May, the statement said, and the camp came under attack from a bridge.
"The exact number of attackers is not known but they came by motorbike and sprayed bullets on the troops from the bridge," a senior security official told AFP on condition of anonymity.
"It is highly likely that the attackers belonged to a banned religious outfit, which is a hand in glove with Taliban."
The official added: "Nobody has so far claimed responsibility of the attack but if we follow the pattern of the attack, it looks similar to assaults that these outfits have been carrying out in different cities."