A BRAZILIAN radio programme broadcast in 1990, “The Meeting of the Rivers”, compared the condition of London's River Thames with São Paulo's Tietê. The Thames had been reborn, starting from when Joseph Bazalgette, a Victorian engineer, began to build sewers that diverted the filth downstream. The Tietê was choking in waste from 33,000 factories and sewage from 13m people, more than four-fifths of it untreated. The river was biologically dead as far as Barra Bonita, 260km downstream from São Paulo city.

The show struck a chord. Newspapers and NGOs joined the campaign to clean up the river. A petition attracted 1.2m signatures. Finally, in 1992, Projeto Tietê was launched.

Unlike many other infrastructure projects in Brazil, this one kept going through hyperinflation, financial crises and changing political leaders. Cheap loans helped the biggest industrial polluters to become cleaner. New water-treatment plants were built and sewage pipes laid.

Twenty years later, the Tietê is still stinking and filthy as it flows darkly through São Paulo. But not for much longer. Today 55% of the city's sewage is treated; by 2018, 85% should be. The state governor, Geraldo Alckmin, is trying to get the 35 municipalities in the Tietê's basin to co-operate: until 2010 Guarulhos, a satellite city of 1.2m people, treated not a drop of its sewage.

São Paulo's pollution now reaches only as far as Salto, 100km downstream. By 2018, says Monica Porto, a water-quality expert at the University of São Paulo, the benefits should be visible—and sniffable—in the city itself.

Cleaning up the Tietê poses more than the usual problems. São Paulo is just 75km from the river's source, so there is less water to dilute what it discharges. Mountain ranges block potential pipe routes to the sea. Average annual rainfall is 150cm and summer storms can bring 7cm in just a few hours. Impermeable roads and pavements aggravate flooding: this year, the river burst its banks three times. The city has grown eightfold since 1950, and much of its population lives in unplanned slums. Some of these are on riverbanks: water companies must often ask the government to remove people illegally settled where they need to work. And even when sewers are built, some households stay unconnected because they are unable or unwilling to pay.

But the virgin floodplains near the river's source are being turned into what officials claim is the world's largest “linear park”, 75km long, complete with cycle lanes so that bikers can keep an eye out for illegal settlements. Sabesp, a water company, is cleaning up 100 of the river's tributaries, building play areas and planting trees along their banks.

Paulistanos used to love their river, says Janes Jorge, whose book, “The River the City Lost”, tells its history. Artists painted it; swimmers and rowers raced on it; families had days out on its islands and banks. Now it would take a brave picnicker to cross highways flanking the river, let alone go for a dip. Sorting out the city's sewage is just a start, Mr Jorge says: much of what sullies the Tietê is rubbish thrown on the street and dust and oil from cars. “The river's problems are an expression of the city's problems—of poverty and environmental degradation.” Its clean-up may show that all this is slowly being overcome.