Boeing has reached a tentative agreement with the U.S. Justice Department that would allow the planemaker to avoid criminal charges for two fatal crashes of its 737 Max jets more than six years ago.

The settlement was disclosed in a federal court filing Friday, just weeks before a trial was set to start June 23 in Fort Worth, Texas. It calls for the company to pay more than $1.1 billion and strengthen quality and safety measures, Justice Department lawyers said.

It’s a stunning turnaround in the long-running legal case. Just last year, Boeing agreed to plead guilty to a criminal conspiracy. But that deal was rejected in December by U.S. District Judge Reed O’Connor, who has been overseeing the case since 2021.