A German court has ruled cities can impose driving bans on the oldest and most polluting diesel cars, in a landmark ruling hailed “a victory for clean air”.

The decision could lead to millions of drivers in Germany having to switch to cleaner cars, or use alternative forms of transport, on days when harmful emissions are particularly high.

Courts in Stuttgart and Dusseldorf had earlier ruled that a ban on diesel cars – of which there are around 15 million in Germany – would be effective, and should be considered.

That decision was appealed by two German states - Baden-Wuerttemberg and North Rhine-Westphalia - but in a court ruling on Tuesday the Federal Administrative Court in Leipzig approved the right for cities to implement a ban.

Judges said the two cities at the centre of the case can include diesel bans in their clean air plans, but have to ensure that any measures are proportionate to the goal of reducing emissions to the legal limit.

The action came after environmental campaigners had sued dozens of German cities, arguing that they have a duty to cut excessive air pollution to protect people’s health.

Germany has persistently broken EU rules on levels of air pollution, with the country’s environment minister, Barbara Hendricks, called to Brussels last month to answer questions.

Commenting on the latest ruling, she said: “The court has not issued any driving bans, but created clarity about the law.

“Driving bans can be avoided, and my goal is and will remain that they do not come into force.”

New petrol and diesel vehicles to be banned from 2040 in bid to tackle pollution

Angela Merkel, the German Chancellor, also sought to downplay the decision, saying it only concerned “individual cities”.

She said: “It’s really not about the entire country and all car owners.”

However, Niklas Schinerl, clean air campaigner at Greenpeace Germany, said the ruling was a “victory for clean air, and shows what’s possible when public health is the priority”.

He added: “Across Europe, decisions like these are making it clear that diesel cars are on the way out.

“It makes no sense to invest in a new diesel now, because it’s only a matter of time before even the newest diesels are either banned or priced out of cities.

“Instead, dirty diesel cars will be replaced by cleaner, greener electric cars, improved cycling infrastructure and sustainable transport that’s good for health and the environment.”

German media reported that a ban in Stuttgart, home to car maker Daimler, would not come into effect until 1 September at the earliest.

Shares in German car companies were down slightly after the decision was announced.

James Thornton, chief executive of ClientEarth, which jointly brought the case with German environmental group DUH, said it was "another huge win for people and a clear example of courts stepping in where government action is found wanting".

Diesel cars, once touted as an environmentally-friendly alternative to petrol vehicles, have become the focus for air quality campaigners in recent years.

The Volkswagen emissions scandal three years ago – when the car maker used in-car software to cheat on US diesel emissions tests – severely dented the vehicles’ reputation as a cleaner alternative.

Thick smog engulfs New Delhi as air pollution peaks in the city Show all 10 1 /10 Thick smog engulfs New Delhi as air pollution peaks in the city Thick smog engulfs New Delhi as air pollution peaks in the city A battery run tricylce rickshaw passes by the Red Fort amid heavy smog in New Delhi AFP/Getty Images Thick smog engulfs New Delhi as air pollution peaks in the city Indian visitors walking through the courtyard of Jama Masjid amid heavy smog AFP/Getty Images Thick smog engulfs New Delhi as air pollution peaks in the city An Indian policeman wearing a protection mask as he works near India Gate AFP/Getty Images Thick smog engulfs New Delhi as air pollution peaks in the city New Delhi during heavy smog REUTERS Thick smog engulfs New Delhi as air pollution peaks in the city Indian commuters wait for transport amid thick blanket of smog on the outskirts of New Delhi AP Thick smog engulfs New Delhi as air pollution peaks in the city Prince Charles and Camilla arrived at Indira Gandhi International Airport surrounded by smog on November 8 Getty Images Thick smog engulfs New Delhi as air pollution peaks in the city Prince Charles and Camilla depart their plane in New Delhi to smog Getty Images Thick smog engulfs New Delhi as air pollution peaks in the city The morning sun is enveloped by a blanket of smog on the outskirts of New Delhi AP Thick smog engulfs New Delhi as air pollution peaks in the city Indian residents walking along a road amid heavy smog AFP/Getty Images Thick smog engulfs New Delhi as air pollution peaks in the city A woman drives a scooter through the morning fog to drop off a child at school AP

In particular, emissions of nitrogen dioxide (NO2), which is linked to lung problems, are several times higher than in petrol vehicles.

Friends of the Earth called the decision “potentially a big step towards cleaning up the country’s polluted air”.

Jenny Bates, the group’s clean air campaigner, called on the British Government to follow Germany’s lead and encourage drivers to switch from diesel vehicles, with a diesel scrappage scheme and a network of “Clean Air Zones”.

In the UK, where major cities also regularly breach EU limits, all sales of new petrol and diesel cars will end by 2040.

London’s new ultra-low emissions zone (ULEZ) will also come into force in April 2019, combining with the congestion charge and existing low emissions zone to impose an additional charge on drivers of the most polluting vehicles.

But campaigners have urged the city’s mayor, Sadiq Khan, to extend the ULEZ from its current central London zone to include the whole of the capital.