BERLIN — Handing environmentalists a landmark victory, a German court ruled Tuesday that cities can ban diesel cars and trucks to combat air pollution, a decision with far-reaching and costly implications in the country where the diesel engine was invented in the 1890s.

The ruling by the Federal Administrative Court stirred fears from motorists, auto dealers and other businesses worried about the financial impact. And Chancellor Angela Merkel's government scrambled to reassure drivers it would seek to prevent such drastic measures by pushing other ways to reduce urban pollution.

Diesel automobiles are a popular alternative to gasoline-powered ones in Germany, with about 9 million diesel cars and several million trucks, buses and other vehicles affected by the ruling.

Overall, 1 in 3 passenger cars in Germany, home to such automakers as Daimler, Volkswagen and BMW, are diesel-powered, though the cleanest, most modern models would probably still be allowed even if cities decided on a ban.

"It's a great day for clean air in Germany," said Juergen Resch, head of the group Environmental Action Germany, which had sued dozens of German cities for failing to meet legally binding emissions limits.

While diesel cars produce less carbon dioxide and tend to get better mileage than gas-powered vehicles, they emit higher levels of nitrogen oxides, or NOx, contributing to respiratory illnesses and 6,000 deaths annually, according to government figures.

Two German states had appealed lower court decisions that suggested bans on particularly dirty diesel cars would be effective. Germany's highest administrative court rejected that appeal Tuesday, effectively instructing two cities at the center of the case — Stuttgart and Duesseldorf — to consider bans as part of their clean air plans.

What comes next is an open question.

It's not clear whether cities will actually move to ban diesels. And if they do so, it remains to be seen whether automakers will be forced to upgrade exhaust and software systems or buy back vehicles; if the government will offer consumers incentives; or if owners will be left on their own, forced to bear the costs.

The Leipzig-based administrative court said cities won't be required to compensate drivers for being unable to use their diesel cars.

Speaking on behalf of automakers, Matthias Wissmann, president of the German Association of the Automotive Industry, stressed that the government could ease the uncertainty by not leaving it to cities to decide on a case-by-case basis.

"We hope it comes to sensible national regulations," he said.

European cities considering diesel bans like Copenhagen and Paris will be watching how the situation plays out in Germany as they make their own decisions.

Jeff Schuster, an analyst with the consulting firm LMC Automotive near Detroit, said diesel bans could spread to other polluted European cities. But he said the market in Europe, China and elsewhere was already headed in that direction because of the big push toward electric vehicles and the damage done by the Volkswagen diesel-emissions cheating scandal.

Diesels make up a smaller part of the American auto market, and so any bans in Europe would have little effect on the U.S., Schuster said. For the past two years in the U.S., only 2.7 percent of registered vehicles were diesel, according to Kelley Blue Book.

New diesel car sales in Germany were already declining in anticipation of the decision, and also because of the VW scandal. Used-car dealers fretted about what the ruling will mean for the vehicles on their lots.

"The prices as well as the demand are going down rapidly," said Marcel del Arbol, owner of R&M used car dealership in Frankfurt. "What happened today will bring the prices down even more.

German car companies dipped on the stock market following the ruling but mostly recovered, with Volkswagen down 0.9 percent at the end of the day, BMW down 0.06 percent and Daimler up 0.2 percent.

Analysts said the ruling might actually prove to be a boon for the economy if drivers choose to upgrade their engines or buy new models.

Merkel sought to downplay the prospect of widespread diesel driving bans, suggesting that many of the 70 German cities that regularly exceed pollution limits might be able to cut harmful emissions with other measures such as software upgrades in vehicles and converting bus and taxi fleets to electric power.

Experts, however, questioned whether bans can be avoided and accused the German government of ignoring the health problems caused by diesel for too long.

Fritz Kuhn, the Green Party mayor of Stuttgart, home to automakers Daimler and Porsche, accused the government of leaving it to cities to clean up the mess by failing to provide a nationwide solution.

Political leaders stressed that diesel owners shouldn't have to shoulder the full burden of a ban.

"The auto industry that caused the harmful emissions has to upgrade diesel engines at its expense," said Kai Wegner, a lawmaker who speaks for Merkel's party on urban issues.

The ruling alarmed groups representing small and medium-size companies. Diesels — first developed by Rudolf Diesel in Augsburg over a century ago — are a mainstay of many company fleets and are widely used by taxi companies and delivery services.

Berlin's Chamber of Commerce said companies in the capital would have to spend 240 million euros ($295 million) to replace their fleets if diesel cars were banned — enough to drive many out of business.