Friday's inferno comes as the government has been waging a major crackdown on fuel theft.
Scores of locals with jerry cans and buckets had been collecting gasoline that was gushing from a leaking pipeline when an explosion occurred, according to witnesses.
Video taken in the aftermath showed desperate people fleeing the scene, screaming for help, as the enormous fire lit up the night sky in Tlahuelilpan, Hidalgo state, 105 kilometres north of Mexico City.
"I went just to see what was happening, and then the explosion happened. I rushed to help people," Fernando Garcia, 47, told AFP. "I had to claw through pieces of people who had already been burned to bits."
The tragedy comes as the federal government is waging a highly publicized war on fuel theft, a problem that cost Mexico an estimated $3 billion in 2017.
President Andres Manuel Lopez Obrador travelled to the scene in the early hours of Saturday.
"I am deeply saddened by the suffering in Tlahuelilpan caused by the explosion of a pipeline," the leftist leader wrote on Twitter. "I call on the whole government to assist people there."
Federal and state firefighters and ambulances run by state oil company Pemex rushed to help victims with burns and take the wounded to hospitals.
The flood of patients overflowed local clinics and hospitals, said AFP correspondents at the scene.
Security Minister Alfonso said around midnight that the fire had been brought under control.
Pemex said it was also responding to another fire at a botched pipeline tap in the central state of Queretaro, though in that case there were no victims.
Mexico is regularly rocked by deadly explosions at illegal pipeline taps, a dangerous but lucrative business whose players include powerful drug cartels and corrupt Pemex insiders.