An illegal garment shop in southern Beijing caught fire early Monday, killing 17 migrant workers and their family members who may not have been able to escape the four-story building because of bars on the windows.
The official Xinhua News Agency said people had to kick out the window bars or leap from the roof to escape.
Another 24 people were injured in the fire, which broke out at 1 a.m. (1 p.m. EST, 1700 GMT Sunday), the agency said. It did not specify the cause of the blaze.
The first-floor garment shop was unlicensed, and the floors above it were used to house workers and their families, Xinhua said. Iron bars installed over windows to keep out burglars may have prevented people from escaping, it added.
"We saw people jumping from the building. About six or seven people, dressed in pajamas, flung themselves from the first floor after kicking open the bars on one window," local resident Wang Xuegang was quoted as saying by Xinhua.
"It was a real nightmare. Some dived from the top floor," said Wang.
The agency quoted Chang Hongyan, the deputy government head of the local Daxing district, as saying most died of smoke inhalation.
Firefighters had trouble reaching the blaze because their trucks couldn't fit down the neighborhood's narrow alleys, Xinhua said.
A survivor identified only by his last name, Xu, was quoted as saying that he broke his legs jumping off the top of the building.
"The first floor was filled with choking fumes. With no way to leave, my wife and I jumped from a platform at the top of the building," Xu said.
Building fires are common in China because of lax safety codes and unsafe construction work. In November, 58 people were killed in a Shanghai apartment fire that was blamed on welders ignoring safety precautions.
Also Monday, Xinhua reported that three workers were injured in an explosion and fire at a pesticide factory in southern China.