German cities will be allowed to ban older diesel vehicles from some areas following a landmark court ruling.
The Federal Administrative Court in Leipzig said the cities of Stuttgart and Duesseldorf could legally ban older, more polluting diesel cars from zones worst affected by pollution.
The ruling sets a precedent for other cities and analysts said it could lead to similar action across Europe.
The government, which had opposed the bans, said they could still be avoided.
The ruling by a top federal court came after German states had appealed against bans imposed by local courts in Stuttgart and Duesseldorf.
The environmental group DUH brought the cases after about 70 German cities exceeded European Union limits for nitrogen oxides (NOx) last year.
Diesel emissions containing nitrogen oxides can cause respiratory disease.
What happens next? Theo Leggett, Business correspondent, BBC News
The likelihood now is that the German government will rush to introduce some sort of national policy, to ensure at least some level of consistency across the country.
It's not just about Germany either - cities across Europe are struggling to meet EU air quality standards, and may well see the German ruling as setting a precedent.
New diesel cars won't be affected, but that's not really the point. Consumers are already moving away from the technology - and the prospect of city bans will only accelerate that process.
So diesel's decline is likely to gather momentum.
That's a problem for the industry, because while diesels produce high levels of nitrogen oxide - a major urban pollutant - they emit relatively low levels of carbon dioxide, a greenhouse gas.
So moves to control one environmental problem may end up undermining efforts to combat another - unless we all start driving electric cars very soon.
Diesel vehicles have faced greater scrutiny since VW's "dieselgate" scandal.
In September 2015, the car maker admitted it had used illegal software to cheat US emissions tests. Some 11 million cars worldwide ended up being affected by the scandal.
DUH said it hoped the bans in German cities would end the industry's "resistance" to refitting older, more-polluting cars to meet the latest EU standards.
ClientEarth, an environmental law firm that worked on the case, said the win was "a tremendous result for people's health in Germany and may have an impact even further afield".
Lead clean air lawyer Ugo Taddei said: "This ruling gives long-awaited legal clarity that diesel restrictions are legally permissible and will unavoidably start a domino effect across the country, with implications for our other legal cases."
The impact on German drivers could be marked, with millions being forced to leave their cars at home on days when harmful emissions are particularly high.
It could also depress the value of diesel cars affected by the ban.
Of the 15 million diesel cars on Germany's roads, only 2.7 million meet the latest Euro-6 standards, according to data from Germany's automotive watchdog.
Car companies could also incur huge costs to refit vehicles at a time when consumer interest in diesel is falling.
The market share for diesel vehicles in Germany fell from 48% in 2015 to around 39% last year.
Seeking to reassure car owners, the government insisted that nothing would change right away and stressed that bans were not inevitable.
"The court has not issued any driving bans but created clarity about the law," said Environment Minister Barbara Hendricks. "Driving bans can be avoided, and my goal is and will remain that they do not come into force," she added.
Chancelor Angela Merkel also weighed in, saying the ruling concerned only "individual cities".
"It's really not about the entire country and all car owners," she said.
Seeking to avert bans, German car makers have pledged software improvements for millions of diesel cars and offered trade-in incentives for older models.
The German government meanwhile has floated alternatives, such as making public transport free in cities suffering from poor air quality.
Paris, Madrid, Mexico City and Athens have all pledged 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.
Carmakers including VW-owned Porsche and Toyota have also signalled they will move away from diesel technology.
Analysts at Evercore ISI said the latest German ruling had "set a strong precedent for similar action across Europe".
"Note, the judge previously commented that the EU has clear rules on emissions and cities have a 'duty' to meet pollution targets."