Terrorists, believed to be three in number, attacked a Central Reserve Police Force camp along the bank of Dal Lake in Srinagar on Thursday.
Two of them were killed and a security officer was injured in the exchange of fire.
The terrorists threw grenades and fired indiscriminately in their attempt to storm the camp, housed in a hotel, CRPF sources said.
The troops fired in retaliation, triggering an hour-long gun battle at the camp's main entrance, in which two of the terrorists were killed, the sources said.
A search was on for the third.
The sub-inspector injured in the attack was hospitalised and his condition was stable, the sources said.
A lesser-known terrorist outfit, the Kashmir Freedom Force, claimed responsibility for the attack.