DETROIT - Volkswagen pleaded guilty Friday to conspiracy and obstruction of justice and agreed to pay a $4.3 billion penalty for a brazen scheme to program nearly 600,000 vehicles to cheat on U.S. emissions tests.

The criminal and civil penalty, if approved by a federal judge, would be the largest ever levied by the U.S. government against an automaker. VW’s total cost of the scandal now has been pegged at about $21 billion, including a pledge to repair or buy back vehicles.

U.S. regulators confronted VW about the software after West Virginia University researchers discovered differences in testing and real-world emissions of harmful nitrogen oxide. Volkswagen at first denied the use of the so-called defeat device but finally admitted it in September 2015.

Even after that admission, company employees were busy deleting computer files and other evidence, VW’s general counsel Manfred Doess acknowledged to U.S. District Judge Sean Cox.

Get Breaking News Delivered to Your Inbox

Summing up the scandal, Assistant U.S. Attorney John Neal said it was a “calculated offense,” not a “momentary lapse of judgment.”

The judge said he wanted more time to study the terms of the punishment negotiated by the U.S. Justice Department, including a $2.8 billion criminal fine. He set a sentencing date of April 21.

“This is a very, very serious offense,” Cox said.

An attorney for 300 VW owners who have opted out of a larger court settlement objected to the penalty, contending that owners were entitled to restitution through the criminal court. But the Justice Department and VW argued that the company agreed to pay $11 billion in restitution to owners through a civil lawsuit, and that was sufficient. That was part of a $15 billion civil settlement with U.S. environmental authorities and car owners approved last year.

Although the cost is staggering and would bankrupt many companies, VW has the money, with $33 billion in cash on hand.

Under its agreement, VW must cooperate in the investigation and let an independent monitor oversee compliance for three years. Separately, seven Volkswagen employees have been charged in the scandal.