German automaker Volkswagen AG will pay more than $15.3 billion to settle charges that it cheated on U.S. diesel emissions tests, an agreement that will fund buybacks for consumers and provide up to $4.7 billion that could benefit makers of cleaner technologies.
The deal formally filed by the Justice Department on Tuesday will provide the largest-ever automotive buyback offer in the United States. The proposed consent decree confirmed that VW (vlkay) will set aside $10.033 billion to cover buybacks or potential fixes for diesel cars and sport utility vehicles that used illegal software to defeat government emissions tests.
Get Data Sheet, Fortune’s technology newsletter.
The settlement goes beyond compensation for consumers. Under the deal, VW will provide a total of $2 billion to fund programs directed by the state of California and the U.S. Environmental Protection Agency to promote construction of electric vehicle charging infrastructure, development of zero-emission vehicle ride-sharing fleets, and other efforts to boost sales of cars that do not burn petroleum.
VW also agreed to put up $2.7 billion that EPA Administrator Gina McCarthy said Tuesday would be used by government and tribal agencies to replace old buses, or fund new infrastructure at ports to reduce diesel emissions.
“It allows folks to take care of infrastructure,” McCarthy said during a news conference on Tuesday. Agencies could “spend money on equipment” that would replace older, dirtier machines.
Also on Tuesday, VW announced a separate settlement with at least 44 U.S. states, the District of Columbia and Puerto Rico that will cost at least $600 million.
However, Deputy U.S. Attorney General Sally Yates said a criminal investigation remained “active and ongoing.”
“By duping regulators, Volkswagen turned nearly half a million American drivers into unwitting accomplices in an unprecedented assault on our environment,” she added.
The settlements stem from VW’s admission in September that it installed secret software that allowed U.S. vehicles to emit up to 40 times legally allowable pollution.
Shares of VW were up 3.2% at 109.50 euros.
The U.S. deal, which covers 475,000 2.0-liter vehicles, would move the company close to the 16.2 billion euros ($18 billion) it has set aside to cover the costs of the scandal.
The actual amount VW will spend on buybacks could be significantly less if regulators approve fixes and owners opt to get vehicles repaired. Most owners will get $5,100 to $10,000 in compensation, including the pre-scandal value of the cars, documents filed on Tuesday said.
The company expects to begin buying back vehicles in October, when a U.S. judge is expected to give final approval to the settlement, and is to start proposing fixes in November. Some vehicles will require significant mechanical work.
VW cannot resell or export the vehicles it buys back unless the U.S. Environmental Protection Agency approves a fix, the documents said. Volkswagen must repair or buy back 85% of the 475,000 vehicles by June 2019 or face penalties of $100 million for every percentage point it falls below that figure.
The settlement does not cover fees for the lawyers of owners suing VW or address 80,000 larger polluting 3.0 liter Porsche, Audi, and VW diesel cars. Also to be decided later is the amount of any civil fine VW faces under the U.S. Clean Air Act for emissions violations.