The rescue was filmed by a migrant construction worker who responded to the incident, after hearing the newborn's cries.
Police officer Qian Feng was first on the scene, saying he saw the child's feet in the toilet pipe before he got down on the ground to pull the baby out.
"The baby’s head was pointing downwards and her whole body had already fallen into the drain," he told the Beijing Times. "We could only see the baby’s feet from the side."
Police are investigating who left the newborn in the public toilet.
Those involved in the rescue expressed sadness at the baby's circumstances.
"I feel so torn and sad," the migrant worker involved in the rescue told CNN. "How could something like this happen?"
Local TV reports quoted neighbours saying the mother may have given birth to the baby directly into the squat toilet, leaving the baby behind.
The two kilogram baby is being treated for infections at a Beijing hospital, but is otherwise uninjured, hospital staff said.
The baby is one of an estimated 10,000 children who are abandoned every year in China.
Historically, under the country's one child policy, a preference for boys meant many abandoned babies were girls.
Today, a number of babies abandoned have physical disabilities.
Share

