A senior police officer said troops of counter insurgency Rashtriya Rifles and the Jammu and Kashmir police jointly surrounded a house in Chattergul village deep in the forest area, 35 kilometres from capital Srinagar, on specific information about presence of a group of militants there.
"The holed up militants were challenged upon to which they opened fire triggering an encounter at the end of which two foreign militants were killed," the officer said.
He said two houses were also destroyed during the gunfight.
Arms and ammunition was also recovered from the debris which is being cleared now by the security forces.
Officials said body of one militant has been recovered from the site of the encounter and search is on for the other.
Although the identity and group affiliation of the militants was not immediately known, a senior police officer said preliminary investigations have revealed that they were foreigners.
"The inmates of the house where the militants were hiding told us that they were speaking a language which they could not comprehend. Probably, they were Afghans or from North West Frontier Province (Khyber Pakhtunhhwa)," SP Ganderbal Shahid Mehraj said.
With inputs from PTI
Will Omar restore his party's pride in Ganderbal?
Terrorists gun down policeman in Srinagar
LeT commander among two militants killed in Kashmir
Brutish Srinagar cops thrash journo unnecessarily
Kashmir: Probe ordered in NC worker's death