The incident happened at Yuanping city's Xuangang Coal Power Company's staff hospital around 2.25am (1825 GMT Sunday), with 17 bodies found by Monday afternoon and two people seriously injured, China Central Television reported.
The explosion occurred in a garage at the hospital and damaged buildings within one square kilometre, Xinhua news agency and a local policeman said, without giving a reason for the blast.
A doctor at the hospital, who declined to give his name, said a two-storey building which housed the garage and a small residential quarters was "completely flattened".
One end of a five-storey residential building for hospital staff was also completely destroyed, he said.
Some of the windows of the main hospital building, which has a capacity of 300 patients, were smashed but the structure appeared not to suffer major damage, the doctor and another staff member said.
Television footage showed most of the windows of the red-brick staff building smashed with rubble scattered across the street.
Rescuers were seen searching for people amid rubble.
"I heard a loud bang," said the doctor who lives in the staff quarters about 500 metres away from the garage. "Many windows in my building were smashed."
The doctor said the blast made a hole between two and three metres in the ground.
A policeman at the Xuanlan township, where the hospital is located, said at least 15 people had been killed and about a dozen people might still be buried in the rubble.
"We estimate that the death toll could reach 30," said the policeman, who declined to give his name.
The cause of the blast was still under investigation, China Central Television and Xinhua news agency said.