The armed men, who were in a car, fired indiscriminately and lobbed grenades at a police station at Badabher on the outskirts of Peshawar.
Police teams intercepted the car and killed the two men in an exchange of fire, officials said.
Three passers-by, including a woman, were injured in the firing.
Several grenades and weapons were found in the car, officials said.
In a separate incident, an alleged target killer and two accomplices was arrested by police from a house at Hangu in Khyber-Pakhtunkhwa province.
Khan claimed the target killer was a commander of the banned Tehrik-e-Taliban Pakistan and was wanted for several murders.