The terror strike took place at the crack of dawn when the militants, believed to be foreign mercenaries, entered the police complex in the worst-hit Pulwama district, 25 km from here.
Police, CRPF and Army personnel quickly swung into action and cornered the militants and ensured that family members of the police personnel living within the complex were taken out to safety.
By afternoon, the security personnel neutralised one of the three terrorist while another militant's body was recovered after 5 PM, officials said, adding the firing had stopped and the third body would be recovered soon.
The militants had entrenched themselves in all the three blocks of the police complex and were firing at the approaching troops, they said.
Lt Gen J S Sandhu, General officer Commanding of Srinagar-based XV Corps, said it is a "fidayeen" (suicide) attack.
Among those killed four were from the CRPF, one was a constable of Jammu and Kashmir Police and three were Special Police Officers working with the state police.
Two of the four CRPF personnel were killed at the fag end of the operation when they were defusing one of the improvised explosive devices planted by the militants.
Director General of Police SP Vaid said it was a sad day for security forces who suffered such a heavy causality.
"However, the boys fought bravely and we are only more determined to wipe out militancy from the entire state," he said.
A police official said that one of the militants came out of a building and fired indiscriminately during the encounter.
"He was gunned down on the spot," the official said.
The authorities have suspended mobile internet services in the district as a precautionary measure.