A 20-year legal nightmare for State Farm Mutual Automobile Insurance Co. appears to finally be over.

On the brink of trial, the company this week agreed to pay $250 million to settle a federal class action suit that accused State Farm and one of its in-house counsel of manipulating the election of an Illinois Supreme Court justice in order to influence the court's vote on an appeal.

The suit alleged State Farm recruited a candidate and heavily funded and directed his campaign through in-house counsel William Shepherd. The newly elected judge then voted to overturn a previous $1 billion verdict against State Farm in state court.

The details of how State Farm and its lawyer, both named defendants in the suit, used dark money funneled through political action committees to fund one of the most expensive judicial campaigns in Illinois history was part of a story, “Is Justice for Sale in Illinois?” in Corporate Counsel magazine in September 2016.

Illinois-based State Farm on Thursday declined to comment beyond a released joint statement that said the company “denies liability, that it considers the claims to be without merit … and that the settlement is made simply to bring an end to the entire litigation.”

The statement also said State Farm “considers that it is settling under the unjust enrichment claim”—and not under the suit's claim for alleged violations of the U.S. Racketeer Influenced and Corrupt Organizations Act (RICO). The company has always denied that it attempted to influence a judge.

The plaintiffs agreed to dismiss both claims. They were represented by Chicago's Clifford Law Offices, along with Ball & Scott; Neal & Harwell; Hausfeld; and Lieff Cabraser Heimann & Bernstein.

Lead co-counsel and firm founder Robert Clifford said in a statement, “This settlement is a victory for the little guy against a national corporation with incredible power, influence and resources.”

State Farm was represented by Taft Stettinius & Hollister; Heyl, Royster, Voelker & Allen; Riley Safer Holmes & Cancila; Quinn Emanuel Urquhart & Sullivan; and Skadden, Arps, Slate, Meagher & Flom, among others.

Under RICO, the company could have faced treble damages of over $8 billion if it lost at trial, which was scheduled to begin on Tuesday in U.S. district court in East St. Louis, Illinois. Presiding Judge David Herndon still must sign off on Tuesday's settlement.

Both parties said they decided to settle “to avoid protracted litigation and appeals that could continue for several more years.”

The case began in the late 1980s when over 4 million policyholders challenged State Farm's use of aftermarket, non-original vehicle parts in repairs. Their class action suit in state court resulted in a $1 billion verdict against the insurer in 1999.

That judgment was reversed by the Illinois Supreme Court in August 2005, after the court sat on the case until a new justice was elected.

During the interim period, Shepherd, while still working for State Farm, co-founded the Illinois Civil Justice League, which engineered the election of Justice Lloyd Karmeier. Plaintiffs claimed State Farm funneled more than $4 million in dark money into Karmeier's campaign.

With Karmeier's vote, State Farm won a split decision overturning the $1 billion verdict. The justice, who has been named chief justice of the court, declined to comment.

The plaintiffs then brought the RICO suit in federal court, and listed Karmeier as a witness had the trial gone forward.

After the settlement, Clifford Law Offices issued a statement with the headline: “State Farm Pays $250 Million to Keep Illinois Chief Justice Off the Witness Stand.”

During an interview on the suit, Joseph Belth, a professor emeritus of insurance at Indiana University and for 40 years the editor of the monthly periodical The Insurance Forum, called it “one of the most troubling cases I've ever seen.”

Also concerned was Bruce Freed, a former longtime journalist on Capitol Hill and now president of the nonprofit Center for Political Accountability in Washington, D.C., who said, “This case raises real questions about buying justice.”

After the settlement this week, plaintiffs lawyer Clifford asked, “Why does a company pay a quarter of a billion dollars to resolve a dispute? State Farm has always maintained its innocence, but history will be the judge and reveal the ultimate truth.”'