The 6.5-magnitude quake was centered in Cipatujah, in the western part of Java, the US Geological Survey said, at a depth of 91.9 kilometers (about 57 miles).
Residents felt the quake about 190 miles away (305 kilometers) in the capital of Jakarta, where people briefly evacuated to the ground floor of their high-rises.
Tremors were also felt in the cities of Bandung, more than 63.5 miles away (102.1 kilometers) and Yogyakarta, more than 211 miles away (339.9 kilometers), authorities said.
A tsunami alert was issued after the quake, which Indonesian authorities recorded at 11:47 p.m. as 6.9 magnitude, according to Sutopo Purwo Nugroho, spokesman for Indonesia's National Disaster Management and Mitigation Agency
The two victims were buried in rubble, one in Ciamis, in West Java, and the other in Pekalongan, in Central Java, emergency officials said.
A few hundred homes and buildings were destroyed or damaged, the officials said. Several hospitals were damaged. Seventy patients from Banyumas Hospital were moved to tents and another temporary shelter.
Fears of a tsunami prompted people to evacuate their homes for higher ground, but there were no reports of tsunamis occurring along the southern coasts of western, central and eastern Java and the city of Yogyakarta.
The alert was lifted at 2:30 a.m., the spokesman said.
Most residents returned to their homes on Saturday and they were advised to seek temporary shelter if their dwellings aren't safe. Several aftershocks continue to be felt in the areas hit by the quake, emergency officials said.
An earthquake on December 7, 2016, struck Indonesia's Aceh province in Sumatra and killed at least 100 people.
Photo caption: Motorists in Cilacap, Indonesia, are stuck in traffic as they try to reach higher ground amid fears of a tsunami after an earthquake. A tsunami warning was canceled.