* Court rules city bans possible even without national rules
* Ruling is an embarrassment for Merkel's government
* Ministers say ban can still be averted
* Decision could force costly emissions cleaning upgrades (Adds details, analyst comment)
By Markus Wacket and Ilona Wissenbach
LEIPZIG/FRANKFURT, Germany, Feb 27 (Reuters) - German cities can ban the most heavily polluting diesel cars from their streets, a court ruled on Tuesday, a move that could accelerate a shift away from the combustion engine and force manufacturers to pay to improve exhaust systems.
The court said Stuttgart, which styles itself the birthplace of the modern automobile and is home to Mercedes-maker Daimler, should consider gradually imposing a year-round ban for older diesel models, while Duesseldorf should also think about curbs.
Many other German cities exceed European Union limits on nitrogen oxide (NOx), known to cause respiratory disease. After the ruling, the northern city of Hamburg said it would start to implement limits on diesel vehicles from the end of April.
There has been a global backlash against diesel-engine cars since leading German carmaker Volkswagen admitted in 2015 to cheating U.S. exhaust tests. The scandal has spread across the industry and boosted investment in electric vehicles.
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. France and Britain will ban new petrol and diesel cars by 2040.
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.
Germany has long promoted diesel to help cut carbon dioxide emissions and meet climate change goals, but the country now fears a shift away from the combustion engine could endanger hundreds of thousands of jobs.
The ruling was praised by environmental groups but angered many politicians and business lobbies who said millions of drivers might end up unable to use or sell vehicles they bought in good faith.
"Driving bans have a massive impact on our ownership rights, on mobility and on our profession," said Hans Peter Wollseifer, president of the association of German tradesmen. "The carmakers are to blame for the diesel problem, not us tradesmen."
The VDA auto industry lobby took comfort from the fact the court had not insisted on bans. "It is a rejection of general driving bans ... They must be proportional and only considered as a last resort," the VDA's Matthias Wissmann said in a statement.
Merkel said the government would discuss with regions and municipalities how to proceed, while her ministers said they still hoped bans could be averted by steps to bolster public transport and get automakers to improve emissions systems.
"We must do everything possible to prevent the loss of personal freedom and the reduction in value of cars," Transport Minister Christian Schmidt told a news conference.
Sales of diesel cars have been falling fast in Europe since the Volkswagen scandal, with fears of driving bans sending demand sharply lower in Germany in the last year.
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.
"This is a great day for clean air in Germany," DUH managing director Juergen Resch said.
"This is a debacle for the policies of the grand coalition, which has sided with the auto industry," Resch added, referring to the ruling coalition of conservatives and Social Democrats that Merkel hopes to renew in the coming weeks.
The court on Tuesday ordered Stuttgart and Duesseldorf to amend their anti-pollution plans, saying city bans could be implemented even without nationwide rules.
"It will not be easy to implement," Stuttgart mayor Fritz Kuhn told a news conference, adding the regional government would probably agree a new plan within six months.
Germany's police union warned it did not have capacity to enforce any bans.
Cars that meet Euro-4 emissions standards could be banned from Stuttgart from next January, while Euro-5 vehicles should not be banned until Sept. 1, 2019, four years after the introduction of the latest Euro-6 standard. Tradesmen and some residents should be exempted, the court added.
Environment Minister Barbara Hendricks said bans could still be avoided if automakers agree to pay to upgrade the exhaust cleaning systems of older diesels.
"The problem was caused by carmakers and we should not release them from their responsibility," she said.
Of the 15 million diesel cars on Germany's roads, only 2.7 million have Euro-6 technology. Evercore ISI has estimated that upgrading the exhaust cleaning of just the Euro-5 fleet could cost up to 14.5 billion euros ($17.9 billion).
"By the time these vehicles face the risk of being banned from certain cities, the industry, together with Berlin, will have found solutions to offer practical hardware updates and attractive scrapping schemes," Evercore ISI analysts said.
The government has begun work on legal changes to permit driving bans on certain routes on an emergency basis, transport ministry documents seen by Reuters showed.
It is also considering making public transport free in cities suffering from poor air quality.
$1 = 0.8118 euros Additional reporting by Andreas Cremer, Maria Sheahan and Tom Sims; Writing by Emma Thomasson; Editing by Keith Weir and Mark Potter