The fragile truce between the Pakistani Taliban and local authorities in Swat valley came to the brink of collapse on Tuesday as militants ambushed a group of soldiers killing two of them, prompting retaliation from the security forces.
The militants attacked a group of soldiers escorting a water tanker in Matta sub-district of Swat, said a statement from the military.
Three soldiers were injured in the "unprovoked firing" by the militants and two of them later succumbed to their injuries.
The attack was "in clear violation of the peace agreement" in Swat, the military said. The militants and the security forces exchanged fire for about an hour.
The security forces are observing "full restraint and complying with the terms and spirit of the peace accord," the military said.
Security forces and the Taliban announced separate ceasefires in Swat last month to facilitate peace talks. Taliban spokesman Muslim Khan claimed the soldiers were attacked because they had moved in the area without informing the militants.