Bodies of the three militants have been recovered and operation has now been called off, a senior police official said.
The official said while two militants were killed last evening, the third ultra put up a stiff resistance.
"The third militant started firing again this morning and was killed around 9.15 AM," he added.
An army officer, Major Mukund Varadarajan, and a soldier were killed while fighting the militants.
Some arms and ammunition were also recovered from the scene of the encounter, he said.
Security forces launched a search operation in Karewa Malino in Shopian, 55 kms from here, last evening following information about presence of three militants - two locals and one foreigner.
The militants were asked to surrender but they resorted to firing, triggering the gunfight.
The identity of the slain militants could not be ascertained immediately.
Shopian is part of the Anantnag Parliamentary constituency and the encounter took place a day after militants carried out an attack on a polling party escorted by police and CRPF in the district at the end of the voting on Thursday.
One polling officer was killed while five others including three security personnel were injured in the incident.