In this photo taken Feb. 14, 2013, a Volkswagen logo is seen on the grill of a Volkswagen on display in Pittsburgh. The Environmental Protection Agency (EPA) says nearly 500,000 Volkswagen and Audi diesel cars built in the past seven year are intentionally violating clean air standards by using software that evades EPA emissions standards. (AP Photo/Gene J. Puskar)

The Environmental Protection Agency said Friday that Volkswagen intentionally skirted clean air laws by using a piece of software that enabled about 500,000 of its diesel cars to emit fewer smog-causing pollutants during testing than in real-world driving conditions.

The agency ordered VW to fix the cars at its own expense. The German automaker also faces billions of dollars in fines, although exact amounts were not determined.

The cars, all built in the last seven years, include the VW Jetta, Beetle, Golf and Passat models, as well as the Audi A3. The vehicles all contain a device programmed to detect when they are undergoing official emissions testing, the EPA said. The cars only turn on full emissions control systems during that testing. The controls are turned off during normal driving situations, the EPA said, allowing the cars to emit more than the legal limit of pollutants.

The EPA called the company's use of the so-called "defeat device" illegal and a threat to public health.

"EPA is committed to making sure that all automakers play by the same rules," said Cynthia Giles, assistant EPA administrator for enforcement and compliance assurance.

The EPA called on VW to fix the cars' emissions systems, but said car owners do not need to take any immediate action. The violations do not present a safety hazard and the cars remain legal to drive and sell while Volkswagen comes up with a plan to recall and repair them, the EPA said.

VW, which also owns Audi, said in a statement it is cooperating with the investigation, but declined further comment.

The EPA said VW faces fines of up to $37,500 per vehicle for the violations—a total of more than $18 billion. No final total was announced. California issued a separate compliance order to VW, and officials announced an investigation by the California Air Resources Board.

Despite the seriousness of the violation, the EPA said VW will be given "a reasonable amount of time to develop a plan to complete the repairs," including both the repair procedure and manufacture of any needed parts.

It could take up to a year to identify corrective actions, develop a recall plan and issue recall notices, the EPA said.

Environmental groups hailed the EPA and California for moving aggressively to enforce clean air laws.

"The charges here are truly appalling: that Volkswagen knowingly installed software that produced much higher smog-forming emissions from diesel vehicles in the real world than in pre-sale tests," said Frank O'Donnell, president of Clean Air Watch, a Washington-based advocacy group.

O'Donnell accused VW of "cheating not just car buyers but the breathing public." He said the charges undercut industry rhetoric about "clean diesel" cars.

The Volkswagens likely perform better with the emissions controls defeated than they do with them on, said Aaron Bragman, Detroit bureau chief for the Cars.com automotive shopping and research site. Otherwise, he said, there would be no reason to have a setting that turns on the controls for tests and turns them off for regular driving.

"Obviously it's changing the way the engine operates somehow that may not be pleasing to consumers," he said. "It would follow that it would put it into a very different feel in terms of operation of the vehicle."

But Bragman said other countries may allow different modes for testing and normal driving.

The allegations cover roughly 482,000 diesel passenger cars sold in the United States since 2008. Affected models include:

— Jetta (model years 2009-15)

— Beetle (model years 2009-15)

— Audi A3 (model years 2009-15)

— Golf (model years 2009-15)

— Passat (model years 2014-15)

Explore further VW recalls 270,000 cars in China to fix airbags

© 2015 The Associated Press. All rights reserved.