The mid-afternoon blast shattered the lower floors of the downtown tower, throwing debris into the streets and sending frightened workers running outside.
A government official, speaking on condition of anonymity, said preliminary findings suggested the blast was caused by a gas boiler exploding in a Pemex building next to the tower. But the cause was still being investigated, the official added.
The explosion was the latest in a series of safety problems to hit Mexico's national oil monopoly.
Interior Minister Miguel Angel Osorio Chong said the blast killed at least 25 people, up from a previous count of 14, and injured 100. Dozens of employees were believed to be still trapped inside, and rescue workers said the death toll at the Pemex skyscraper could keep rising.
Mauricio Parra, a paramedic at the scene, said he believed at least 20 people had died and that 100 could be trapped at the offices of Pemex, a national institution that President Enrique Pena Nieto's administration has pledged to reform this year.
Police quickly cordoned off the building, and television images showed the explosion caused major damage to the ground floor and blew out windows on the lower floors of the tower.
"You could feel it all through the building," said Mario Guzman, a Pemex worker who was on the 10th floor of the building, which is more than 50 floors high.
First mistaking the blast for an earthquake, Guzman, who said he escaped after running down the stairs, feared the building would collapse on top of him and his colleagues, "and that we would end up like a sandwich."
Several witnesses said the blast came from the neighboring Pemex building. Pemex said initially the tower was evacuated due to a problem with its electricity supply. It then said there had been an explosion, but did not say what caused it.
Earlier in the evening, Pena Nieto, who took office in December, went to the scene of the blast and said it would be thoroughly investigated. He vowed to apply "the force of the law" if anyone was found to be responsible for it.
Mexican news network Milenio said security officials after the explosion carried out a precautionary search of Congress for explosive devices, but found nothing.
Helicopters buzzed around the building and lines of fire trucks sped to the entrance, while emergency workers ferried injured people through wreckage strewn on the street.
Search-and-rescue dogs were sent into the skyscraper, a Mexico City landmark that sports a distinctive "hat" on top. Pemex published a list of 105 workers who were being treated for injuries in hospitals.
Some families of people working in the tower were impatient for news about missing relatives.
Gloria Garcia, 53, herself a Pemex worker who was not in the building during the explosion, came to see if she could track down her son, who worked in one of the floors hit.
"I'm calling his phone and he's not answering," Garcia said, weeping as she called repeatedly on her phone. "Nobody knows anything. They won't let me through. I want to see my son whatever state he's in."
Pemex has experienced a number of deadly accidents in recent years and lesser safety problems have been a regular occurrence. In September, 30 people died after an explosion at a Pemex natural gas facility in northern Mexico.
More than 300 were killed when a Pemex natural gas plant on the outskirts of Mexico City exploded in 1984.
Eight years later, about 200 people were killed and 1,500 injured after a series of underground gas explosions in Guadalajara, Mexico's second biggest city. An official investigation found Pemex was partly to blame.
Alberto Islas, a security analyst at consultancy Risk Evaluation, said the explosion at the Pemex offices was another blot against the company's safety record.
"We've seen this time and again at Pemex. They don't have a well-integrated policy," Islas said, noting it would probably take several hours before investigators would be able to determine the cause of the explosion.
Pemex, a symbol of Mexican self-sufficiency since the oil industry was nationalized in 1938, has been held back by inefficiency and corruption and by the burden it shoulders of providing about a third of federal tax revenues.
Pena Nieto has pledged to open up the company to more private investment to improve its performance.