The fighting broke out when militants – suspected to be pro-independence fighters – ambushed a paramilitary convoy on Saturday, killing two troopers before taking refuge in the building on the outskirts of the state capital Srinagar.
“All the three militants have been killed in the gunbattle. Their bodies have been recovered,” the inspector general of police for the region, Javaid Gillani, told AFP.
The heavily-armed militants, who are fighting against Indian rule over the disputed Himalayan region, allowed more than 120 people including trainees and staff to flee from the building after holing up there.
Soldiers and police surrounded it and fired mortar bombs, while the militants responded with automatic weapons and hand grenades.
On Sunday two captains and a special forces soldier were killed as the gunbattle raged.
A gardener died in the initial crossfire and 13 members of the Central Reserve Police Force were wounded.
As the battle raged, hundreds of local residents came onto the streets in support of the freedom fighters, chanting slogans against Indian rule.
Part of Jammu and Kashmir has been occupied by India since the partition in 1947.
Since 1989 Kashmiris have been fighting Indian soldiers deployed in the territory, demanding either independence or a merger of the region with Pakistan.
Tens of thousands, mostly civilians, have died, due to atrocities by Indian army in the occupied territory.
Last week police ordered residents to stay indoors during gunbattles with pro-Independence natives, triggered by the killing of two students in similar protests.
Overall violence in the region has sharply declined during the last decade but armed clashes between local fighters and government forces still occur regularly.