Mr. Johnson admitted to Mr. Ayala that the Volkswagens contained a defeat device. Mr. Ayala was furious. Volkswagen had knowingly squandered California taxpayer dollars, and allowed polluting vehicles to stay on California highways.

“They wasted our time,” Mr. Ayala said. “It had a very significant, very real impact on us all.”

A lawyer for Mr. Johnson, who has not been charged, declined to comment. In a statement, David Massey, a lawyer for Mr. Schmidt, said: “At its core, the government’s case against Mr. Schmidt is based on a fundamental misunderstanding of what happened on two occasions when Mr. Schmidt spoke to regulators in August 2015.”

As word spread inside Volkswagen that the regulators knew about the illegal software, employees began trying to cover their tracks. At an Aug. 31 meeting, an in-house lawyer suggested that engineers in attendance should check their documents. Several of those present interpreted the comment as a signal that they should delete anything related to the emissions issue in the United States. In the weeks that followed 40 employees at Volkswagen and the company’s Audi division destroyed thousands of documents.

On Sept. 3, 2015, Volkswagen formally admitted to regulators that 500,000 diesel vehicles in the United States had two calibrations, one for tests and one for normal operation — in other words, a defeat device. Mr. Winterkorn resigned before the end of the month, while insisting he had no knowledge of the wrongdoing.

The research begun with a $70,000 grant eventually cost Volkswagen more than $22 billion in fines and legal settlements, far more than the cost of equipping the cars with adequate pollution control equipment in the first place.

No one was more surprised at the outcome than the team at West Virginia University. “We never set out to get crosswise with anyone,” said Dan Carder, who oversaw the Volkswagen research as director of the university’s Center for Alternative Fuels, Engines and Emissions. “We were just kind of doing our jobs.”