A day after the European Commission lodged a complaint with Europe's top court against Germany for its repeated failure to protect air quality in its cities, the details of the German ruling will add to pressure on Volkswagen and its German peers to provide hardware fixes for polluting diesel models.
Research firm Evercore ISI has said this could cost the industry 14.5 billion euros (£12.6 billion).
Germany opened the door to diesel bans in February when it allowed environmental groups to sue cities which fail to enforce Europe's clean air rules, despite fierce lobbying to oppose bans from carmakers.
Dozens of German cities including Hamburg, Munich and Stuttgart exceed European Union limits on nitrogen oxide (NOx), known to cause respiratory disease.
In a 30-page statement on the ruling which was published on Friday, Germany's administrative court in Leipzig said there should be no grace periods for driving bans.
"Such restrictions, in their intensity, do not go beyond other passage and stopping bans as justified by road law requirements, which motorists always have to reckon with and which they principally have to accept," the court said.
European carmakers have invested heavily in diesel engines, which produce less of the carbon that causes global warming than gasoline, but more of other pollutants blamed for causing disease. Germany's move to allow cities to ban diesel engines from streets could have wide implications for the future of the industry.
Bans in the home of some of the world's biggest automakers are a further blow for the sector, and an embarrassment for Chancellor Angela Merkel's government, which has faced criticism for its close ties to the industry.
"This ruling is a disaster for the government which one-sidedly stands in for the greed for profit by the carmakers while leaving 10 million owners of manipulated diesel cars alone," said Juergen Resch, managing director of Germany's DUH environmental lobby.
Immediate driving bans on major roads or road sections would be legitimate and could affect all models excluding those meeting the latest Euro-6 emissions standards, the ruling statement said.
Of the 15 million diesel cars on Germany's roads, only 2.7 million have Euro-6 technology which was phased in in 2014.
For wider city areas encompassing a multitude of main roads and side streets, the court recommended a phased implementation of bans, starting with older cars that meet Euro-4 emissions standards. The Euro-4 standard was replaced by Euro-5 beginning in 2009.
Germany's VDA auto industry lobby urged cities to keep a sense of proportion when deciding their course of action, noting that NOx levels should fall significantly in coming months as more Euro-6 models are sold and the emissions-control software of older models is updated.
"What's at stake are not blanket driving bans but an assessment as to whether local measures are even necessary to meet the legal air quality targets," VDA president Bernhard Mattes said.
The Leipzig court had said in February that Euro-5 vehicles should not be banned until Sept. 1, 2019. Tradesmen and some residents too should be exempted, it said at the time.
The ruling is the latest regulatory action to come in the wake of Volkswagen's diesel emissions test-cheating scandal in 2015, and was prompted by legal action from Germany's DUH.
"The courts have been waiting for the ruling statement received today," said Remo Klinger, a lawyer representing DUH which is pushing suits in 28 German cities including Munich and Frankfurt.
"We believe that in many cases, it will swiftly come to oral hearings and rulings."
Germany's second most populous city Hamburg on Wednesday said it had started putting up signs to enforce driving bans of older diesel cars, with local authorities expecting restrictions to start taking effect at the end of this month.
(Reporting by Andreas Cremer; Editing by Raissa Kasolowsky)