The city forked over a staggering $20 million to put to rest one of New York’s biggest environmental and legal controversies – sandblasting to remove toxic lead paint from the Williamsburg Bridge.

But in a “Damned if I Do, Damned if I Don’t” scenario, the city ended up cutting the check to the bridge contractor, in the city’s largest legal payout this year, The Post has learned.

The city eventually suspended the reviled blasting procedure after outraged residents from the Lower East Side and Brooklyn bordering the bridge filed lawsuits claiming it posed a health hazard.

Paint chips and clouds of paint dust had wafted over their neighborhoods in 1992. Lead paint can cause brain and nerve damage, particularly if ingested by young children.

But after city officials banned the blasting in 1996 following unfavorable court rulings, the major contractor – Perini Construction – sued the city, alleging breach of contract.

The blasting was part of the original $155 million contract to renovate the dilapidated bridge. As an alternative, the construction crews had to resort to using a tedious, labor-intensive chemical process, which required additional manpower and eight months of delays.

“It was like going from a bulldozer to a teaspoon,” said Henry Goldberg, the Rockville Centre, L.I., lawyer representing Perini Construction.

Perini filed nine lawsuits to collect a whopping $160 million in additional payments above the original contract caused by the change orders, city officials said.

The city Law Department defended the settlement, which was forged during 28 meetings over three years.

“Based on circumstances that were discovered after work began, the contractor made claims of approximately $160 million. We believe the final settlement – $19.75 million – was in both parties’ best interest and was favorable to the city,” said City Corporation Counsel Michael Cardozo.

Goldberg said the city will soon cut another check for more than $440,000 – bringing the total settlement to about $20.2 million.

Brooklyn Assemblyman Joseph Lentol, part of the coalition that opposed the blasting, said he had no regrets that the city had to shell out some $20 million.

“I don’t care how many millions of dollars it cost the city. People’s lives are more important,” he said.