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.