The extent of damage or injuries was not immediately clear, but people fled office buildings along the central Reforma Avenue.
Mexico's seismological agency calculated its preliminary magnitude at 6.8 and said its center was east of the city in the state of Puebla.
Pictures fell from walls and objects were shaken off of flat surfaces. Some people dove for cover under desks.
Earlier in the day buildings across the city held preparation drills on the anniversary of the 1985 quake.