The magnitude 7.2 quake was centered in the southwestern state of Guerrero, close to the Pacific beach resort of Acapulco, the U.S. Geological Survey (USGS) said.
Some residents of the capital ran outdoors in their pajamas after the quake. Electricity was cut off in parts of the city and some residents said paintings fell off the walls while small parts of masonry crumbled inside apartment buildings.
Luis Felipe Puente, head of the Mexican government's emergency services, said there were no immediate reports of damage and the U.S. Pacific Warning Center said it did not expect the quake to trigger a destructive tsunami.
Nevertheless, residents of the capital were shaken by the quake, one of the biggest to hit Mexico in several years.
"I had to hold on to a tree, like a drunk," said Pedro Hernandez, 68, a doorman working in central Mexico City.
The USGS said the quake, was centered some 37 km (23 miles) north of the municipality of Tecpan de Galeana in Guerrero.
The earthquake was relatively shallow, at a depth of about 24 km (15 miles), and was felt as far away as the states Puebla and Tlaxcala in central eastern Mexico.
Angel Aguirre, the governor of Guerrero, a state frequently struck by earthquakes, said there were no reports of major damage or deaths, but that checks were still being made.
An employee of the Fairmont hotel in Acapulco, said the situation was calm and that guests had returned to the building.
"The structure is fine," the woman, who identified herself only as Ana, said by telephone.
Cesar Sanchez, 24, a student living in Guerrero's capital Chilpancingo said he got a big shock when the tremors began.
"I was in bed, and some things fell that have never fallen. The dogs outside were barking and barking," Sanchez said.
A devastating 8.1-magnitude earthquake in 1985 killed thousands of people in Mexico City. In March 2012, a 7.4 magnitude quake hit Mexico but did not cause major damage.