Police open fire on demonstrators demanding a new college in their town.
H K Lohia, a senior police official, said that all five hostages were unharmed in the encounter.
Kashmiri mosques have been used as safehouses for hostage-takers in the past, leaving security forces with the dilemma of whether to risk a public backlash in the Muslim-majority state by pursuing them.
A standoff at Kashmir’s holiest mosque, Hazratbal, lasted 34 days in 1993, ending when the separatist fighters were given safe passage without their weapons.
But a two-month siege in 1995 of another Muslim shrine, Chrar-e-Sharief, resulted in fierce fighting that killed 17 people and destroyed the holy site.
Kashmir is experiencing an insurgency against Indian rule that has claimed tens of thousands of lives since it began in 1989.