Still, for weeks, the parties could not agree on a crucial aspect of the deal: how much money to compensate Volkswagen owners. On several occasions, one plaintiff’s lawyer looked nervously at a replica Prohibition-era Tommy gun mounted on Mr. Mueller’s wall.  “If the director had his F.B.I. badge and machine gun, he might have shot us all,” said the plaintiff’s lawyer, Joseph F. Rice, who spent many late nights at Mr. Mueller’s law offices in Washington, negotiating on behalf of Volkswagen owners.  Soon, the lack of personal time for the negotiators became a cruel, running joke. At periodic conferences with the parties in San Francisco, Judge Breyer would repeatedly refer to the long days the lawyers were putting in, at sacrifice to their families, to groans from those assembled.  On April 21, the lawyers met another deadline set by the judge to reach a preliminary agreement. It called for Volkswagen to buy back or fix diesels starting with the 2009 model year, to compensate owners and to pay money to offset the environmental damage it had caused.  While they had the broad outlines, they still needed to work out the details.  In the weeks that followed, number-crunchers from all sides fed proposed figures and situations into financial models during negotiations. But each step forward was fraught. At one point, talks about how to value the cars bogged down over misunderstandings of whether negotiators were calculating median versus mean values, which would result in substantially different settlement sums.  There were many questions. How many cars were out there? How many might have been wrecked and no longer on the roads? What were the taxes people paid? What was the car worth in September 2015, when the scandal broke in the United States?  “We were basically trying to determine how much consumers overpaid for the car based on the false advertising — in time, in extra taxes,” said James Kohm, an associate director of the Federal Trade Commission, which was involved in the talks. “But I could say $50 billion, somebody could say $4 trillion.”  Despite its weak position, Volkswagen won some important concessions, like not having to bring all the diesels into full compliance with air-quality rules. Government officials realized, the negotiators said, that some customers would want to keep their cars and that there needed to be a solution that reduced pollution as much as possible.  The compromise also cut the potential cost to Volkswagen. It could save billions if many customers opted for repairs, which are less expensive for the company than buybacks.  Instead, the company will pay $2.7 billion into a fund overseen by a court-appointed trustee that will be used for projects to reduce nitrogen oxides. Volkswagen will also invest $2 billion to build charging stations and other projects to promote the use of electric vehicles. About $1 billion will go to California, which has the largest number of Volkswagen diesels.  In the final days before the June settlement deadline set by Judge Breyer, negotiators gathered at the Washington offices of Sullivan & Cromwell, which represented Volkswagen, at a large conference room overlooking the Jefferson Memorial.  One of the last issues was to get state attorneys general, who had sued separately, to sign on to the deal, according to three participants in the discussions. Negotiations with Texas, a crucial state because it accounted for 43,000 of the affected vehicles, continued until around midnight on June 27, just hours before the settlement was due.  Negotiators agreed that Texas would get $50 million in fines and fees as part of the settlement money. With Texas, 44 states, along with the District of Columbia and Puerto Rico, were on board, enough to claim victory.  The next morning, Sally Q. Yates, deputy attorney general of the United States, walked in front of cameras to announce steps to right what she called “an unprecedented assault on our country’s environment.”  “But let me be clear,” Ms. Yates said, “it is by no means the last step.” She notably said that criminal inquiries into Volkswagen’s conduct would continue.  Judge Breyer drove that point home at a conference in San Francisco a day later, warning that the settlement had some notable loose ends. The deal, for example, offers no solution for the 85,000 larger Volkswagen, Audi and Porsche vehicles. And the settlement is still subject to formal approval by the judge, which is expected to be granted.  At the conference, the judge turned to Mr. Giuffra, one of the Sullivan & Cromwell lawyers who negotiated on Volkswagen’s behalf. Mr. Giuffra had often said that the negotiations took him away from his 9-year-old son.  “I’m just going to have to tell you,” the judge said, “that to get acquainted with your son may take a bit longer.”  Correction: July 15, 2016 An earlier version of this article described incorrectly the position of one Volkswagen official who went on a humility tour. Manfred Döss, Volkswagen’s general counsel, is not a member of Volkswagen’s management board. An earlier version also misstated the number of states on board with the settlement after Texas joined the group. It was 44, not 42.  A version of this article appears in print on July 16, 2016, on page B1 of the New York edition with the headline: Behind a VW Settlement: Speed, Compromise and a Determined Judge. Order Reprints| Today's Paper|Subscribe
It was one of the fastest civil settlements in the history of corporate malfeasance, but fraught with pitfalls, including clashing egos and cultures.