Police were called out to Xi'an Road in Hongkou District after receiving a report at 7:35 a.m., said a spokesman for the Public Security Bureau of Hongkou.
A 50-year-old woman and a 46-year-old man died and five of the 18 people taken to hospital were critically ill.
The residential area had been cordoned off.
Police are investigating the cause of the accident. Witnesses said a gas pipeline leakage was possibly to blame for the accident.