Attempts to evict thousands of people squatting in a makeshift protest camp in a northern Indian city ended in deadly clashes as people opened fire from treetops and police retaliated, leaving at least 24 people dead, authorities have said.

More than 370 people have been arrested for their alleged part in the overnight violence, during which gas cylinders being used by the protesters for cooking exploded and ignited a fire that killed 11 people, said Daljit Chaudhary, a senior state police officer, on Friday.

Two officers were shot at when the violence began late on Thursday in Mathura, an ancient Hindu temple city on the Yamuna river about 200 miles south-west of Lucknow in Uttar Pradesh, Chaudhary said. More than 100 people were injured in the melee, including 23 police officers hospitalised with injuries including bullet wounds.

The standoff had been building for nearly two years, during which thousands had occupied a 268-acre patch of government land while demanding that officials build public facilities and lower petrol prices, now at about $1 (69p) a litre. Over time, the protest camp grew with tents and cooking gear, with thousands of men, women and children using it as a makeshift home.

The camp engulfed by flames on Thursday. Photograph: STR/AFP/Getty Images

In April, the high court in Allahabad ordered the occupiers to leave. When they refused, police obtained a court order for eviction and on Thursday sent a group of officers to force the squatters out.

The protesters had gathered to resist the eviction, and about 100 of them attacked the officers, including some who opened fire from treetops while others hurled stones and hit officers with sticks, according to Javed Ahmed, the director general of the state police force.

“We knew they had firearms, but we didn’t expect them to fire at us the way they did,” Ahmed said. “They appeared to be well trained in handling arms.”

Police sent in about 500 reinforcements to clear the area and evict the squatters by Thursday night, he said. More than 170 rifles and 40 homemade revolvers were seized, and police were searching for more weapons and suspects on Friday.

“The culprits will not be spared at any cost. The police had gone there to vacate land following court orders,” said Akhilesh Yadav, the chief minister in Uttar Pradesh.

The protesters had reportedly been referring to themselves as an independence force following the example of Subhas Chandra Bose, one of India’s independence leaders who went missing during a military operation in 1945.