A top German court ruled in favour of allowing major cities to ban the most heavily polluting diesel cars, a move set to hit the value of 12 million vehicles in Europe's largest car market and probably force carmakers to pay for costly modifications.

There has been a global backlash against diesel-engine cars since Volkswagen admitted in 2015 to cheating US exhaust tests, meant to limit emissions of particulate matter and nitrogen oxide (NOx), known to cause respiratory disease.

While other countries are also considering restrictions on diesel cars, a ban in the birthplace of the modern automobile is a new blow for the car industry, and an embarrassment for Chancellor Angela Merkel's government.

The government, which has come under fire for its close ties to the car industry, had lobbied against a ban, fearing it could anger millions of drivers and disrupt traffic.

The ruling by the country's highest federal administrative court came after German states had appealed against bans imposed by local courts in Stuttgart and Duesseldorf in cases brought by environmental group DUH over poor air quality.

The court rejected the appeals by the state governments and ordered Stuttgart and Duesseldorf to amend their anti-pollution plans, saying that city bans can be implemented even without nationwide rules.

"This is a great day for clean air in Germany," DUH managing director Juergen Resch said.

DUH sued Stuttgart and Duesseldorf to force them to implement driving bans, after about 70 German cities were found to exceed European Union NOx limits.

Sales of diesel cars have been falling fast in Europe since the Volkswagen scandal, with fears of driving bans sending demand sharply down in Germany in the last year.

Paris, Madrid, Mexico City and Athens have said they plan to ban diesel vehicles from city centres by 2025, while the mayor of Copenhagen wants to ban new diesel cars from entering the city as soon as next year.

The share of diesel cars in overall vehicle production in Europe could be cut to 27% by 2025 from 52% in 2015, Barclays forecasts.

Germany's government and the auto industry have been seeking to avert driving bans.

Carmakers have pledged to overhaul software on 5.3 million diesel cars and are offering trade-in incentives for older models to help improve air quality.

But environmental groups have lobbied for costly improvements to exhaust cleaning systems for cars with Euro-6and Euro-5 emissions standards.

"Once it is clear there will be driving bans the car industry will end its resistance against technical upgrades," DUH's Resch earlier told public broadcaster Bayern 2.