Bayer has agreed to spend more than $12 billion to resolve thousands of U.S. lawsuits and deal with future claims, taking its biggest step so far in resolving headaches the German chemical giant inherited in its acquisition of Monsanto Co.

Agreements were reached on about 95,000 claims filed over Roundup, part of a Bayer plan to spend about $11 billion to settle all litigation over the widely used herbicide, the company said Wednesday. Bayer also will pay as much as $820 million to settle toxic-pollution claims and make a $400-million payment for farmers whose crops were damaged by its herbicide based on the chemical dicamba.

Taken together, the accords resolve a trio of major litigation risks that tagged along with Bayer’s $63-billion purchase of Monsanto in 2018. Roundup claims — the biggest liability — surged after big U.S. court losses, and the share decline wiped tens of billions of dollars off Bayer’s market value. Getting past the legal drama is a top priority for Chief Executive Werner Baumann.

Bayer’s American depositary receipts climbed on the settlement news, gaining as much as as 5%. The ADRs, which represent one-quarter of a regular share, rose 15 cents to $20.54 in New York.

Though a Roundup settlement had been expected, Sebastian Bray, an analyst at Berenberg, said deals covering other litigation at a cost most investors will find reasonable were a pleasant surprise. It’s a “big relief” and “should allow investors to draw a line under the saga of the last two years,” Bray said via email.

The Roundup agreements will resolve 75% of about 125,000 claims that have either been filed or were set to be filed, the Leverkusen, Germany, company said in a statement. Bayer said it will pay $10.1 billion to $10.9 billion to resolve all current lawsuits, including $1.25 billion set aside for future claims handled as part of a class action lawsuit.

Separately, Bayer agreed after about nine months of settlement talks to resolve most claims by cities and ports over contamination by polychlorinated biphenyls, or PCBs, a chemical solely made by Monsanto that is used as a cooling agent in heavy equipment. The settlement came on the eve of a trial in Spokane, Wash.

Bayer officials also agreed to pay $400 million to resolve claims that its dicamba herbicide drifted onto the fields of neighboring farmers and damaged their crops. No lawsuits are required for the payouts, but farmers must show proof of crop damage or reduced yields tied to dicamba contamination, the company said.

“We believe the settlement will be sufficient to resolve all legitimate claims in this litigation,” Don Downing, one of the plaintiffs’ lawyers leading the Missouri-based dicamba cases, said in an interview.

In the Roundup settlements, Bayer executives said the deal shouldn’t affect its credit rating or dividend policy and that paying down its large debt load from the Monsanto transaction remains a “high priority.” Payments can be funded with cash on hand, future free-cash flow, the sale of Bayer’s animal-health unit and potentially by issuing bonds, company officials said.

Still, the cost of resolving most of the litigation will slow the company’s ability to pay down debt, Moritz Melsbach, an analyst for Moody’s, said in a statement.

Under the terms of the Roundup settlement, Bayer will set up a $1.25-billion fund to cover future cancer claims. That money will also be used to provide financial assistance to struggling cancer patients and support research into whether glyphosate — the weedkiller’s active ingredient — is a carcinogen, the company said.

Individual payouts may range from several hundred thousand dollars per case to less than $50,000.

The accord allows Bayer to continue selling Roundup in the U.S. for use in backyards and farms without any safety warning, and plaintiffs’ attorneys who settled their case inventories agreed to stop taking new Roundup clients.

It estimated there are still about 30,000 current cases yet to be settled. The company also is refusing to settle the three damage verdicts totaling more than $191 million, which are on appeal. Bayer is doing the same thing in dicamba, pressing efforts to have a $265-million verdict on behalf of a Missouri peach farmer tossed.

Former users of Roundup blame glyphosate for their non-Hodgkin’s lymphoma and other cancers. The company denies glyphosate is a carcinogen, a position backed by the U.S. Environmental Protection Agency. A federal judge ruled this week that California officials can’t force companies to place warning labels on glyphosate-based products.

Lawyers representing some of the Roundup users who declined to settle their claims vowed Wednesday to continue bringing cases to trial. Three California juries in a row ruled against the company and ordered it to pay damages to former Roundup users. The next cases could be brought in state court in St. Louis.

“The remaining cases are in the hands of lawyers who know how to litigate, so we’re going to see some more Roundup trials in the future,” said Fletch Trammell, a Texas lawyer who held his roughly 5,000 cases out of the settlement. “This litigation is far from over.”

Bayer faced a surge in new lawsuits last year after it lost the U.S. jury trials, and investors issued a rare rebuke to Baumann last spring. Some, including Elliott Management Corp., urged the company to seek a comprehensive settlement.

Since last summer, Baumann has kept Bayer out of more trials while engaging in high-stakes mediation talks. In April, he won the annual confidence vote from 93% of shareholders amid signs that Bayer might soon reach a resolution.

Still, given the Roundup settlement’s hefty price tag, investors may continue to question whether the Monsanto takeover will ever be worth what Bayer paid, Markus Mayer, an analyst at Baader Bank, said via email. And, he said, Bayer’s management may not be safe.