BEIJING — At night on the edges of Beijing, the migrant workers who keep China’s capital city fed, cleaned, swept and supplied wait in fear of a knock on the door that could ruin their hopes of finding a better life.

Far from the skyscrapers and monuments downtown, squads of police and safety inspectors have been scouring the city’s sprawling outer neighborhoods crowded with laborers from poor rural China. Those living or working in buildings deemed to be dangerous or illegal are ordered to vacate, sometimes with just a few hours’ notice, before homes, shops and even whole factories are demolished.

Tens of thousands have already been uprooted in the city’s most aggressive drive against migrant neighborhoods that people can recall; many more migrants are wondering how much longer they can remain in their homes, or even in Beijing.

The city government says they are being pushed out for their own safety, after a recent deadly fire in a migrant settlement. But many migrants say the government is using the fire as an excuse to ramp up efforts to drive them out and ease pressures in a city whose population has already soared beyond 20 million people.