Fire and emergency services received a call around 1800 GMT on Wednesday about a gas explosion in the Angelo slum east of Johannesburg.
But on arrival they discovered it was "a gas leakage from a cylinder" containing a "poisonous gas," emergency services spokesman William Ntladi said.
He said the cause of the incident "is alleged to be a nitrate oxide gas leakage from the cylinder used in an illegal mining activity in and around the settlement."
"Apparently, the illegal miners used the gas to extrapolate gold out of the soil," he said.
Gauteng Province Premier Panyaza Lesufi said investigations were under way to determine how the leak happened and what type of gas was involved.
"The scene was heartbreaking," he said, adding that one person had died in a hospital overnight, raising the death toll to 17, while four others were in critical condition.
A spokesperson for the Disaster and Emergency Management Services in Ekurhuleni municipality, where the disaster occurred, linked it to illegal mining
When they arrived at the scene near the middle-class suburb of Boksburg, first responders found scores of people "lying all over the area, due to inhalation of this toxic gas," Ntladi said.
Thousands of unregistered miners scavenge obsolete mines for gold under arduous and often perilous conditions.
South Africa's commercial hub, Johannesburg, and its surrounding areas are built around mountainous dumps of soil and cavernous pits left behind by generations of mining companies that started extracting during a gold rush in the 1880s.
The same suburb was also the scene of a massive gas tanker explosion that killed 41 people on Christmas Eve last year, after a truck carrying liquefied petroleum gas (LPG) got stuck under a bridge, triggering a leak and blast.
This report was compiled from Reuters and Agence France-Presse.