AUGUSTA, Maine — Volkswagen and its affiliates Audi and Porsche, as well as their American subsidiaries, have agreed to pay more than $157 million to 10 states — including $5.1 million for Maine — to settle environmental lawsuits filed last year challenging the companies’ secret use of unlawful “defeat device” software in their vehicles, state Attorney General Janet Mills announced Thursday.

The software caused tens of thousands of tons of excess harmful pollutants to be emitted into the air in Maine and other states, she said in a prepared statement.

Mills joined other states and the federal government in an investigation into the German car maker in September 2015.

The settlement marks the first time that Maine and the other settling states — all of which have adopted California’s stringent vehicle emission standards — have secured an environmental settlement from an automobile manufacturer for violations of their own state auto emissions laws.

Maine will continue to enforce the tough auto emission standards established by California and incorporated into Maine law, Mills said in the news release.

“We will not tolerate the flouting of our state’s environmental laws, the legacy of Senators Ed Muskie and George Mitchell. We will enforce Maine’s environmental standards stringently,” the attorney general said.

“Our air, water and natural resources and the health of our people are critically important,” she said. “The actions by VW to deliberately violate Maine’s motor vehicle emission standards affected all of us and it was important to bring this action on behalf of the people of Maine.”

Maine’s $5.1 million share of Thursday’s agreement with VW represents the largest settlement for Clean Air Act violations that Maine has ever obtained, according to Mills.

The settlement amount reflects payment of more than $1,285 for each defeat-device-equipped Porsche, Audi and Volkswagen diesel vehicle sold or leased in the state. In addition to the amounts the companies already have agreed to pay, the settlement is designed to deter other companies considering breaking Maine’s environmental laws, Mills said.

The settlement money will fund environmentally beneficial projects and programs across the state.

Also as part of the settlement, Volkswagen has agreed to substantially increase its commitment to the emerging electric car market. The agreement requires Volkswagen to, by 2020, at least triple the number of electric car models its Volkswagen, Porsche and Audi brands offer from one model to three, including two electric SUVs.

This settlement agreement was filed Thursday in U.S. District Court for the Northern District of California, and consent judgments also will be filed in the respective state courts, according to Thursday’s release. The other states joining in the settlement are Connecticut, Delaware, Massachusetts, New York, Oregon, Pennsylvania, Rhode Island, Vermont and Washington.

The lawsuit followed an extensive investigation by a multistate coalition of more than 40 states and other jurisdictions.

As alleged in Maine’s complaint, Volkswagen, Audi and Porsche sold more than 570,000 2.0- and 3.0-liter diesel vehicles in the U.S. equipped with “defeat device” software intended to circumvent emissions standards for certain air pollutants.

Once installed, the software activates required emissions controls during a car inspection but deactivates those controls during regular driving, effectively falsifying the inspection results and allowing nitrogen oxide emissions up to 35 times the legal limit.

The devices were in more than 3,500 Volkswagen, Audi and Porsche vehicles sold in Maine before these vehicles were pulled from the market in 2015.

Nitrogen oxide contributes to the formation of harmful ground-level ozone, which is linked to a number of respiratory- and cardiovascular-related health problems, including premature death.