BEIJING—China is careening toward a demographic time bomb. In another decade, it will have more people over 60 than the entire population of the U.S. Its workforce is shrinking, and not enough babies are being born.

Yet when Li Yuanyuan, a professor, was expecting her third child last year, her employer in the eastern city of Qingdao pressured her to end the pregnancy or resign. She refused, but the stress gave her nightmares. “How can I not worry about it?” she said during her pregnancy. “We could end up raising three children...