The Environmental Protection Agency on Friday ordered Volkswagen to fix nearly 500,000 VW and Audi diesel cars that the agency said are intentionally violating clean air laws by using software that evades EPA emissions standards.

VW, which owns Audi, faces billions of dollars in fines, although exact amounts were not determined.

The cars, all built in the last seven years, include a device programmed to detect when they are undergoing official emissions testing, the EPA said, adding that the cars only turn on full emissions control systems during that testing. The controls are turned off during normal driving situations, the EPA said.

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, the EPA said.

The German automaker 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 -- 2015)

.  Beetle (Model Years 2009 -- 2015)

.  Audi A3 (Model Years 2009 -- 2015)

.  Golf (Model Years 2009 -- 2015)

.  Passat (Model Years 2014-2015)