Raids by security forces in Khyber Pakhtunkhwa province triggered gunfights with militants.
At least 15 militants and two soldiers have been killed in two separate gun battles in northwest Pakistan, officials said on Wednesday.
Soldiers on Tuesday conducted a raid on a village in the Swabi district in Khyber Pakhtunkhwa province, triggering a gunfight.
"During exchange of fire Capt Junaid and Sepoy Amjad embraced martyrdom," said a military statement, adding, "Five terrorists killed during the operation."
Security forces stormed a second compound in a nearby village on Wednesday, killing 10 militants, a senior security official told AFP.
The shootouts come after a recent resurgence in militant violence, with 130 people killed nationwide in February, ending a lull in Pakistan's long battle against terrorism.
Taliban militants executed
Separately, the military said in a statement that five Taliban militants who had been sentenced to death were executed on Wednesday at a prison in the northwestern garrison town of Kohat.
Pakistan created special military courts by constitutional amendment after the country's deadliest ever attack in 2014.
The assault on a school in northwestern Peshawar, in which gunmen killed more than 150 people – mostly children – traumatised a country already grimly accustomed to atrocities.
Pakistan's military announced the launch of a nationwide anti-terrorist operation in the wake of the violence last month.