MASAYA, Nicaragua — It is the most irregular of armies.

Armed only with homemade mortars, their features hidden behind scarves and ski masks, the fighters of Masaya crouched behind the barricades they built to protect the streets of their rebellious city.

Shots rang out, answered by the dull thud of improvised explosives, as the volunteers tried on Tuesday to hold off the advance of paramilitary forces and police officers toward the city center. As the assailants broke through each barricade, the defenders sprinted back through the empty streets, past families watching from doorways, poised to bolt inside at the first sign of danger.

But in the end, the resistance was no match for the firepower and men sent by the government of President Daniel Ortega on Tuesday to rescue the police commander who had been assigned to quell Masaya, only to be held hostage for weeks at police headquarters.

A day that began to the ringing of church bells, sounded to alert Masaya’s citizens, ended with at least four dead and more than 30 injured, but the town remained defiant.