JAKARTA, Indonesia — A strong earthquake shook Indonesia's densely populated Java island on Friday night, killing two people and severely damaging dozens of homes near the epicenter.

The magnitude 6.5 quake struck at 11:47 p.m. and was felt across the island, including about 200 kilometers (124 miles) away in the capital Jakarta, where office towers and apartment buildings swayed. Powerful tremors lasted as much as 30 seconds in places.

Residents gather outside their apartment blocks in Jakarta on early Dec. 16, 2017, following after a strong earthquake measuring 6.5 on the Richter scale. Dessy Sagita / AFP - Getty Images

Panicking people ran out of buildings in many areas and roads were clogged with motorbikes, cars and trucks as people fled coastal areas in fear of a tsunami.

Ahmad Solihin, a food vendor in a coastal area of the Sukabumi region, said his village was jolted by a 20-second tremor that cracked walls in his home. He fled on his motorbike with his wife and two children after neighbors shouted that water was coming, he said.

"People suddenly started running so I joined them," said Solihin. More than 1,000 villagers in his area evacuated to higher ground and didn't return until Saturday morning after authorities convinced them it was safe, he said.

A 62-year-old man and an 80-year-old woman were killed in building collapses, said National Disaster Mitigation Agency spokesman Sutopo Purwo Nugroho.

Damage was heaviest in the Tasikmalaya, Pangandaran and Ciamis regions of West Java Province near the epicenter.

More than 40 houses collapsed and about 65 suffered severe damage, said Nugroho.

An Indonesian man walks out of a damaged house as he checks on his belongings after the 6.5 magnitude earthquake hit Tasikmalaya, West Java, Indonesia on December 16, 2017. STR / EPA

The earthquake was about 91 kilometers (56 miles) deep and located just inland, the U.S. Geological Survey said. It triggered a tsunami warning for parts of Java's coastline that was lifted about two hours later. No significant waves were reported.

Several hospitals were damaged by the shaking and patients evacuated.

Indonesia sits on the "Pacific Ring of Fire" and has frequent earthquakes and volcanic eruptions.