Volkswagen has been ordered to recall almost 500,000 diesel cars by the United States government after it emerged that it had used computer software to cheat clean-air laws.

The Environmental Protection Agency is investigating the German car-maker for intentionally using the sophisticated computer program to circumvent nitrogen oxide emissions rules for its diesel cars – making them appear up to 40 times cleaner in tests.

The agency slammed the use of the so-called "defeat device" as "illegal and a threat to public health". It has told the company to fix the cars at its own expense and has imposed at least $18 billion in fines, with exact amounts to be 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, the EPA said, allowing the cars to emit more than the legal limit of pollutants.

The Beetle is among the models affected (AFP/Getty)

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

The manufacturer 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, which could take up to a year.

Frank O'Donnell, president of Clean Air Watch, an evrionmental campaign group, said: "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."

Mr 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.

Watch more