SAN FRANCISCO (AP) — A federal judge approved the largest auto-scandal settlement in U.S. history Tuesday, giving nearly a half-million Volkswagen owners and leaseholders the choice between selling their cars back or having them repaired so they don’t cheat on emissions tests and spew excess pollution.

U.S. District Judge Charles Breyer said the nearly $15 billion deal “adequately and fairly” compensates consumers and gets the polluting vehicles off the road as soon as possible.

The German automaker acknowledged last year that about 475,000 Volkswagens and Audis with 2-liter, four-cylinder diesel engines were programmed to cheat on emissions tests.

Under the agreement, owners can choose to have Volkswagen buy back their vehicle regardless of its condition for the full trade-in price on Sept. 18, 2015, when the scandal broke, or pay for repairs. Either way, Volkswagen also will pay owners $5,100 to $10,000, depending on the age of the car and whether the owner had it prior to Sept. 18 of last year.

Volkswagen has agreed to spend up to $10 billion compensating consumers and could start buying back the cars as early as next month. Regulators have not approved any fixes.

The settlement also includes $2.7 billion for unspecified environmental mitigation and $2 billion to promote zero-emissions vehicles.

“We’re going to sell it back as soon as humanly possible and try to put this behind us,” said Joe Azam, a 35-year-old attorney in New York who owns a 2014 Jetta wagon.

Still, Azam said he thought Volkswagen “got off easy” in how much it was paying vehicle owners.

Blair Stewart, a 2012 Jetta wagon owner in Palo Alto, California, said Volkswagen should have paid owners the full purchase price of their vehicle, given the company’s fraud.

“This is not enough to deter the kind of behavior they did,” he said.

Breyer concluded that affected car owners were not entitled to a full refund because many had “received a great deal of use out of their vehicles.” He also raised the specter of bankruptcy for Volkswagen if it had to pay the full purchase price.

The scandal has damaged Volkswagen’s reputation and hurt its sales. The company is still facing potentially billions more in fines and penalties and possible criminal charges. It also will pay up to $332.5 million in attorney fees and costs and up to $1.2 billion to its U.S. dealers.

The settlement’s approval “is an important milestone in our journey to making things right in the United States,” Hinrich J. Woebcken, president and CEO of Volkswagen Group of America Inc. said in a statement. “Volkswagen is committed to ensuring that the program is now carried out as seamlessly as possible for our affected customers and has devoted significant resources and personnel to making their experience a positive one.”

The lead attorney for car owners, Elizabeth Cabraser, said in a statement that the deal “holds Volkswagen accountable for its illegal behavior and breach of consumer trust.” More than 330,000 people have signed up for settlement benefits, with about 3,200 opting out, she told the judge last week.

Peggy Schaeffer, a North Carolina librarian with a diesel 2010 Jetta wagon, said she was pleased with the settlement terms and has submitted her buyback paperwork. She expects to get close to $15,000 for a car she bought for $16,000 in 2010.

“It’s hard to be grumpy about that,” she said.

The company said in April that it has set aside $18.2 billion to cover the cost of the global scandal, which erupted last year when the U.S. Environmental Protection Agency said Volkswagen had fitted many of its cars with software to fool emissions tests. Car owners and the U.S. Department of Justice sued.

The software recognized when the cars were being tested on a treadmill and turned on pollution controls. The controls were turned off when the cars returned to the road. The EPA alleged the scheme let the cars spew up to 40 times the allowable limit of nitrogen oxide, which can cause respiratory problems in humans.

Through September, VW Group’s sales in the U.S. are down nearly 7 percent from 2015 figures, to just under 386,000 vehicles. The Volkswagen brand fared worse, with sales down 12.5 percent, to just over 231,000 vehicles, according to Autodata Corp. The VW Group includes the Audi, VW, Bentley and Lamborghini brands.

The settlement releases legal claims from most of the 2-liter engine owners, but it doesn’t affect larger 3-liter, six-cylinder diesels, which also cheated on tests. It also doesn’t end claims against parts supplier Robert Bosch, which drew up the cheating software.