Thousands of people fled their homes in panic on Saturday after an accidental explosion at an oil well on Indonesia's Java island but no immediate casualties were reported, police said.

The blast occurred shortly after midnight inside the Pertamina-PetroChina oil refinery complex at Bojonegoro in East Java province, local police chief Herri Wibowo said.

Some 6,000 residents living in three villages beside the complex fled in panic when huge darts of fire shot up into the sky after the blast, Wibowo told AFP.

Almost 150 people were taken to hospital after inhaling pungent ammonia gas spewed out by the burning oil reservoir.

"It was purely accident and fortunately, the fire on the well was put out after five hours. Workers contained the leaking gas from the reservoir by setting it on fire so that it evaporates," Wibowo said.

No casualties among residents had been reported but police were yet to receive any information on deaths or injuries from the oil refinery operators themselves, Wibowo said.

Up to 6,000 people from the three villages were sheltering in mosques and government offices in Bojonegoro, he said.