The residents of Maogang looked on in despair as first dozens, then hundreds, and ultimately 10,164 dead pigs were pulled out of the Huangpu River.

This small town south-west of Shanghai is near the Xietanggang water intake for the Songjiang Water Pumping Station and one of the four main sources of water for Shanghai.

"We don't dare drink the river water," said one villager. The township government has had to bring in a week's worth of drinking water.

The pigs are believed to have floated downstream from Shaoxing, in the neighbouring province of Zhejiang.

It's a new problem, but the causes – waterway pollution and failures to manage rivers across administrative boundaries and government departments – are old complaints.

"Dead pigs have always ended up in Shanghai. This time they just went there by river, instead of by truck," said one Shaoxing pig farmer, pointing at a porcine corpse.

Illegal selling of dead meat

It was only two years ago that pigs started to be dumped in the river. "In the past you could sell them, so they didn't end up in the river." The pig farmers all referred back to a court case two years ago, which shocked the city.

Everyone in Shaoxing knows about the case, which saw 17 people tried. In November 2012, the three ringleaders were given life sentences.

It was a typical tale for a pig-farming village. Dong Guoquan and two others ran an illegal butcherhouse, buying in dead pigs. "They got them cheap, one yuan or so per jin." One farmer explained that a young pig which died of illness would weigh less than 50 jin, an older one no more than 100 [one jin is half a kilogram].

But that didn't do business any harm. The city's intermediate court found that in only two years Dong and the others had bought and butchered 77,000 pigs and sold the meat on for 8.65 million yuan. Most of them came from the townships of Fengqiao, where the village is, and Xinfeng.

"Once they'd been arrested nobody wanted to risk buying up dead pigs openly," 57-year old villager Guo Yue (not his real name) told Southern Weekend. His village of Zhulin, in Xinfeng, is famous for supplying pigs to Hong Kong.

But that meant more pigs were getting thrown in the river. Environmental protection staff in the Songjiang district of Shanghai said they'd taken a trip up river all the way to a concrete plant in Pinghu, Shanghai. Traces of dead pigs were visible all along the route.

A worker on a dredger boat in Caoqiao, Pinghu, said that on March 17, when they had already been working for a week, his boat was still pulling out over 20 pig carcasses a day.

"We do it every year at this time," said a Zhulin villager responsible for the work. The fishermen all change jobs for a while and start catching pigs.

A Zhejiang environmental protection report in 2011 found that 7.7 million pigs were being farmed in Shaoxing. On average 2% to 4% will die, which means between 150,000 and 300,000 corpses need to be disposed of.

"If dumped, they cause bacterial and viral pollution, as well as 20,000 to 30,000 tonnes of chemical oxygen demand," the report said.

But, still, there are no provisions for proper disposal in place. Many officials – including Chen Yunhua, village secretary in Zhulin; Yuan Liqiang, deputy neighbourhood head in Caoqiao; and Dong Yue, deputy neighbourhood head in Yuantong – said that it was only in 2011, that Shaoxing saw any large scale construction of disposal pits.

But it's been nowhere near enough. Zhulin is a major pig farming village, but Chen Yunhua explained that there are only seven pits, with an eighth being built.

Others pointed out that one pit can handle three to five thousand corpses. But according to the Shaoxing Daily, 18,400 pigs died in the village in just the first two months of the year. Capacity is overstretched. "The rest just get dumped in the fields or the river," the villagers say.

Officials try to limit pig farming

A Shaoxing government report admitted that: "the dumping of pigs which have died of illness happens to varying degrees in all districts of Shaoxing."

"The dead pigs weren't a big problem in the past, it was pollution from the farming," said Wang Yubing, deputy at the Pinghu Environmental Protection Bureau. Pinghu borders the Shanghai district of Jinshan and is upriver of the city, and pollution from pig farms further upriver in Nanhu and Haiyan damage water quality.

"The biggest pollution problem for Shaoxing is poultry and livestock farming," said Xu Luzhong, an inspector with the Zhejiang environmental authorities, when he visited the city. Pig excrement, slurry and the corpses dumped all over mean that the beautiful water town is giving off a bit of a stink.

"There are 130,000 farmers raising over 7 million pigs. Each pig excretes as much as 6 or 7 adult humans," said Yu Hongwei, deputy of the city's environmental bureau.

"The government are trying to limit numbers, persuading us to change jobs," said Chen Yunhua. To cut pig numbers, in 2011 the city set up zones where pig farming was banned or limited, including in Zhulin: "By 2015, pig numbers will be reduced from 7.5 million to about 2 million." And no pigs may be farmed within 200 metres of minor waterways, and within 100 metres of more important ones, Chen said.

This was intended to improve worsening water quality. A source with the Shaoxing environmental authorities said that despite the measures the city accounted for two of the locations named and shamed when the provincial bureau checked water quality province-wide. Both the urban centre and the wider city had water of sub-Class 5, the worst level of water quality.

And this pollution ends up in the Huangpu River. National People's Congress representative and professor at East China Normal University Chen Zhenlou said that agricultural chemicals from upstream threaten water quality.

Shanghai relies on water from outside its boundaries, a major headache for its government. It has never managed to do anything effective about upstream pollution.

"The waterways in Shaoxing are just so complex it's a struggle to monitor them," complained Ren Weiliang, deputy of the Pinghu water authorities. There are 3,458 waterways in Pinghu alone, stretching for 2,256 kilometres.

And pig farmers are usually very small operations, which makes them harder to regulate. Yuan Liqiang says that most of the farmers in his jurisdiction are households keeping pigs in their yards. There's so many of them that "sometimes it really is hard to keep control."

The way waterways are managed is also being re-thought. Ren Weiliang explained that in the past the port, urban, water and environmental authorities were all involved.

"Sometimes they see waste floating downstream but can't do anything," said Ren. Pinghu is considering changing the way that works. And to solve problems with cross-boundary coordination the Shaoxing water authorities have set up mechanisms in Xinfeng, Fengqiao and Caoqiao, with boundary rivers being divided up into stretches assigned to different towns.

But those efforts don't connect up with Shanghai. Zheng Zheng, director of Fudan University Basin Pollution Control Research Center, said that it is currently easy for blind spots to arise between upper and lower stretches of rivers. Shanghai is powerless to regulate its rivers upstream. "We can't enforce the law, or issue punishments," Zheng said.

"When pollution crosses boundaries, people try and pass the buck," Zheng continued. In the end nobody knows who should pay. "A tracing mechanism would solve it." He went on to explain this would mean 24-hour monitoring, so "as soon as you notice something coming from upstream, it's the upstream government's problem – as for which specific body or authority, they can figure that out themselves."

But water quality on the upper Huangpu – a long-standing source of drinking water – has long been badly damaged. "Water quality on other tributaries was Class 5 or worse as far back as 2004," recalled one official who participated in a meeting on preventing pollution in important watersheds that year.

Maogang is located by an important source of water, but is still powerless. On January 10 this year, two months before the pig scandal, a leak from a boat carrying chemical containers forced the nearby pumping station to halt work.

To avoid these risks, Shanghai has been forced to look for alternative ways to quench its thirst. "From the sources of the Huangpu to building the Qingcaosha Reservoir at the mouth of the Yangtze, Shanghai is looking for safer water," said Chen Zhenlou. But the Yangtze isn't any safer, and its water quality it also under threat.

So Shanghai is even looking at desalinisation. The latest idea is to take water from Qiandao Lake in Zhejiang – "more than 2 billion cubic metres a year."

• Originally published in Southern Weekend. With contributions from Southern Weekend intern Wang Yue.