The gunfight broke out when security forces launched a search operation at Kakapora in Rishipora village following specific information about the presence of militants there.
As security forces zeroed in on their target, the holed up ultras fired at them, police said.
Security force personnel retaliated triggering a gunbattle that lasted four hours.
Two militants were killed in the gunfight, police said adding the identity and group affiliation of the slain ultras were not yet known.
A group of youths pelted stones at police as the dead militants were believed to be locals.