German environmentalists are hailing a court decision they say could spell the death of diesel.
Stuttgart and Dusseldorf will be allowed to ban older vehicles from their worst polluted areas as a result of the ruling.
Environmental Action Germany (DUH), the group which brought the case, believes it could lead to similar action across Europe.
"It is a great day for clean air in Germany. We fought for clean air for the people who are living in cities," said Juergen Resch, DUH managing director. "The Federal Administrative Court agreed with us on all points. Bans of diesel cars are legal. The court also expressed that the European legislation and health protection are more important than national regulations."
With around 70 German cities exceeding EU limits for dangerous nitrogen oxides (NOx), Greenpeace have described the landmark decision as a tremendous victory.
Greenpeace spokesman Niklas Schinerl said: "This gives communities the possibility to protect people's health even more. Diesel bans are some of the possibilities we have to protect the health of people in cities."
The ruling could affect the value of millions of cars on German roads but the government has stressed that nothing will change right away and that a ban is not "inevitable".