Indonesia's meteorology agency (BMKG) said the earthquake hit 52 km (32 miles) off Banten province at a depth of 10 km, but did not trigger a tsunami warning. The magnitude was initially reported at 6.7 but downgraded to 6.6.
There were no immediate reports of casualties and BMKG warned people to stay indoors, after five aftershocks were recorded, the strongest reaching a magnitude of 5.7.
"From inside a house, it felt like a truck was passing through," BMKG chief Dwikorita Karnawati told a livestreamed news conference.
In Jakarta, tremors were felt strongly for more than a minute, said Reuters witnesses.
Indonesia straddles the so-called "Pacific Ring of Fire", a highly seismically active zone, where different plates on the earth’s crust meet and create a large number of earthquakes and volcanoes.
"I was very scared, suddenly there was a quake and it was so strong," said 38-year-old nanny, Ani, who uses only one name.
"When I felt it I directly grabbed my employer's baby and ran downstairs."
Another resident, Ade, 34, was on the 15th floor of a Banten apartment.
"I was in a Zoom meeting when people all shouted 'Earthquake!'," said Ade, who declined to give her second name.
"The tremors were so strong and I was in shock, I couldn't immediately get downstairs, I needed to steady my body."
The quake was also felt in the provinces of West Java and Lampung, on Sumatra island.
The agency said it had received initial reports of damage in Pandeglang in Banten, but provided no further details.
Speaking to Kompas TV, Banten governor Wahidin Halim said four homes had been damaged, one Islamic school had collapsed, and cracks appeared at a mosque.
Last month, a 7.4-magnitude earthquake struck the country's east, triggering a tsunami warning and also sending residents fleeing from their homes but causing only minor damage.