The quake struck at a depth of 91 kilometres just outside the coastal town of Cipatujah on Java island late yesterday (Dec 15), the US Geological Survey said.
The tremor was felt across the island including in the capital Jakarta, some 300 kilometres from the epicentre.
A 62-year-old man in Ciamis and an 80-year-old woman in Pekalongan city were killed when the buildings they were in collapsed, national disaster mitigation agency spokesman Sutopo Purwo Nugroho said.
“Several hospitals in several areas have also been damaged and patients had to be evacuated,” Nugroho said.
A hospital in Banyumas suffered damaged ceilings, cracked walls and leaks to oxygen pipelines, forcing about 70 patients to be moved to temporary shelters.
At least a hundred houses were damaged across West Java and Central Java provinces, the national disaster mitigation agency said.
The agency was still evaluating the impact of the disaster and urged people to be cautious and stay alert.
Jakarta resident Web Warouw, 50, was on the 18th floor of a building in the capital when the quake struck just before midnight local time.
“Suddenly, we felt dizzy... We then realised it was a quake and immediately ran downstairs,” Warouw said.
Indonesia experiences frequent seismic and volcanic activity due to its position on the Pacific “Ring of Fire”, where tectonic plates collide.
Some 170,000 lives were lost when a 9.1-magnitude quake and tsunami struck Aceh in December 2004, which also hit coastal areas as far away as Somalia.
An earthquake struck the country’s western Aceh province again in December 2016, killing more than 100 people, injuring many more and leaving tens of thousands homeless.