A powerful earthquake of magnitude 7.4 struck southern Mexico's Pacific coast on Tuesday,killing at least four people and cutting off isolated villages,and causing tremors hundreds of miles away in Mexico City.

The fatalities were near the quake's epicenter in Oaxaca, a mountainous state known for its coffee, mescal and Spanish colonial architecture.

Rockfalls blocked the winding mountain roads between the state capital of Oaxaca city and the coast. A clinic and other buildings in hill villages near the epicenter were severely damaged, images on social media showed.

The dead included a worker from state oil company Pemex, who suffered a bad fall, Mexico's civil protection agency said. Pemex was forced to briefly shutter the country's biggest oil refinery in Oaxaca.

Buildings hundreds of miles away in Mexico City shook strongly and people ran out into the streets when an early warning seismic alarm sounded. Two people were injured and more than 30 buildings in the capital suffered damage, officials said.

Videos on social media showed water that apparently came from rooftop pools cascading down residential buildings.

Several old churches in Oaxaca were damaged, including one with a dome at risk of collapse, the protection agency said.

"At the moment we have no preliminary reports of any damage. Several institutions are continuing to evaluate their priority infrastructure," David Leon, the national co-ordinator of Mexico's Civil Protection force, told Milenio TV station.

Oaxaca Governor Alejandro Murat wrote on Twitter that the state was activating safety protocols "to monitor the streets and keep the population protected."

Mexico City mayor Claudia Sheinbaum also activated response protocols, although she said there had been "no major incidents" reported.

The earthquake was felt in several parts of the capital of 8.8 million people which in 2017 was hit by a 7.1 magnitude quake that left 360 people dead throughout the country.

That same year, 96 people died after an 8.1 magnitude quake struck the south of the country, with Oaxaca the worst affected state.

The quake has hit at a time when Mexico is already reeling from the coronavirus pandemic.

It has suffered more than 22,500 Covid-19 deaths - the second most in Latin America - and 185,000 cases.