Rescuers toiled through the rubble of the Maternity and Children's Hospital in the Cuajimalpa borough to look for people who were trapped following the blast, said civil protection chief Fausto Lugo.
City mayor Miguel Angel Mancera told MVS Radio that the area was evacuated "for safety because a lot of the people are babies in the crib area."
Television images showed people with bloodied faces being carried to ambulances. Around 40 percent of the hospital was destroyed.
Officials said two people died, including one woman found under the collapsed structure.
More From This Section
Mancera said at least 32 adults and 22 children were injured, though none were in serious condition. Most were hit by shattered glass.
Lugo said 37 people were transferred to other hospitals.
Mexico has been hit by other gas explosion tragedies in recent years.
In May 2013, 25 people died when a gas tanker's container came loose on a highway north of Mexico City, setting nearby homes and cars on fire.