The security forces launched a cordon and search operation in Khudpora area on Saturday evening following information about presence of the militants there, a police official said.
He said the search operation turned into an encounter after the militants opened fire towards the security forces, who retaliated.
Two militants were killed in the encounter while two others managed to escape, he said.
"A couple of terrorists managed to escape from the site as blood trails have been seen there," he added.
The slain militants have been identified as Mohammad Irfan Bhat and Shahid Mir.
While Bhat had joined militant ranks last year, Mir was part of an arms case from 2004, a police spokesperson said.
"Incriminating material, including arms and ammunition, have been recovered from the encounter site. Police have registered a case and started investigations," he said.