Under a deal approved Tuesday by the federal government, the U.S. Bureau of Reclamation would shed its costly obligation to provide drainage to the Westlands Water District and in exchange, forgive the district’s $350 million debt to federal taxpayers.

Also adopted by Westlands, the agreement must still be approved by Congress. It would end a long legal battle over hundreds of thousands of acres of badly drained farmland that lie within Westlands boundaries on the west side of the San Joaquin Valley.

While Westlands would assume responsibility for managing its tainted drain water, it is unclear how the district would do that, or to what degree the federal government would vet the drainage work.

A spokesman for the reclamation bureau said details of the deal would be made public after it is filed Wednesday in U.S. District Court in Fresno.

Officials have said the terms are essentially the same as those outlined in a 2013 draft agreement: The reclamation bureau would be relieved of the court-ordered requirement to provide drainage to Westlands cropland. The district would permanently retire 100,000 acres of ill-drained fields and agree to a cap on water deliveries that amounts to 75% of its current contract amount.

In return, the reclamation bureau would let Westlands off the hook for the roughly $350 million the district still owes U.S. taxpayers for construction of a portion of Central Valley Project facilities that store and deliver the irrigation water. The government would lift limits on the size of Westlands farms eligible for subsidized water deliveries. And it would give the district an open-ended water contract that wouldn’t be subject to periodic renewal or negotiation.

Federal and Westlands officials said the settlement would save the government more than $3 billion in potential drainage costs.

“Without the settlement, the financial liability mandated by a court-imposed obligation would jeopardize important investments in conservation, environmental restoration and water infrastructure,” Bureau of Reclamation Commissioner Estevan Lopez said in a statement.

But critics immediately condemned the agreement as a sweetheart deal for California’s most politically influential irrigation district — one that would permanently lock in Westland’s access to bountiful amounts of cheap water with no guarantee that the drainage problems would be solved in an environmentally sound manner.

Barbara Barrigan-Parrilla of Restore the Delta, an advocacy group, said: “The Obama administration is making a terrible mistake that will haunt us for generations to come.”

Thanks to local geology and a high water table, the soil in a good portion of Westlands is loaded with mineral salts and selenium, a natural trace element. The salts are harmful to crops when drawn into the root zone. And when concentrated in field drainage, the selenium reaches levels that are toxic to wildlife.

After waterfowl in the Kesterson National Wildlife Refuge were poisoned by Westlands drain water in the 1980s, the reclamation bureau shut down the region’s master drain. That led to decades of legal wrangling and ultimately a court order that the federal government was required to provide drainage under the original legislation that authorized extension of the Central Valley Project to the arid west side of the San Joaquin Valley.

In 2007, the reclamation bureau proposed a $2.7-billion project that would have permanently retired 200,000 acres of badly drained cropland and also called for treatment facilities to cleanse tainted drain water from other fields.

The high price tag doomed the proposal, spurring continued negotiations to settle the issue.

Under the settlement, Westlands’ water contract would be converted to a different type and annual deliveries would be capped at 75% of the 1.2 million acre-feet a year Westlands is currently entitled to. The district would be subject to the same shortage provisions as under its existing contract, reclamation officials said. (In recent decades, Westlands has gotten full deliveries only a handful of times due to drought and environmental restrictions).

But the new contract would be indefinite, locking in the quantity of water Westlands growers are entitled to — an amount that would remain far more than Los Angeles uses in a year. And with the district no longer owing any capital debt, its water costs drop.