XIGUOZHUANG, China—For decades, an army of migrant workers drove China’s boom times, flocking to its cities to sew T-shirts, assemble iPhones, or build apartment blocks and Olympic stadiums.

The arrangement helped millions of poor, rural Chinese join a new consumer class, though many also paid a heavy price.

Now, many migrant workers struggle...