ÖHRINGEN, Germany — Öhringen lies deep in automaking country, homeland of Germany’s biggest industry and a source of national pride. And by most appearances, life is pretty good.

The unemployment rate in Öhringen is a mere 2.3%. Restaurants, nursing homes and kindergartens are begging for workers. The city government is using bulging tax receipts to build a new secondary school and a hospital.

But just outside Öhringen’s tidy old quarter, dominated by the steeple of a 15th-century stone church, there are signs that the economic upswing that has nourished this idyll is beginning to falter.

A factory that makes air filters is closing, putting 240 people out of work. The plant, owned by Mahle, an auto parts manufacturer based in nearby Stuttgart, is a victim of forces that are reshaping the auto industry and threatening the foundation of the German economy.

Global car sales are declining at the same time that companies are pouring billions of dollars into new technologies like autonomous driving and electric cars, which are easier to assemble and require fewer workers and fewer parts.

Carmakers, including Daimler and Volkswagen’s Audi division, as well as suppliers like Continental and Bosch, have announced tens of thousands of job cuts in recent weeks. German auto production will be at a 22-year low in 2019 and 2020, according to calculations by Ferdinand Dudenhöffer, a professor at the University of Duisburg-Essen.

Workers are feeling the brunt, and not just in Germany. The upheaval in auto technology was an undercurrent in the United Automobile Workers’ recent strike against General Motors, with GM aiming for flexibility in staffing levels as it devotes more resources to electric vehicles.

The growing popularity of electric vehicles could force a shift in the balance of power in the global car business that would have long-term consequences for Germany.

So far, sales of electric cars make up a small share of the overall auto market, but they are growing fast. In October, battery-powered cars and hybrids accounted for almost 10% of new car registrations in Europe, according to JATO, a market research firm; figures from another firm, LMC Automotive, put the share at less than 4% in the U.S. Sales of those cars in Europe were up 40% from a year earlier in an otherwise stagnant market.

If the trend continues, it spells trouble for the hundreds of suppliers that make parts for internal combustion engines. The Mahle factory in Öhringen makes equipment that controls the flow of air in diesel and gasoline motors.

“There is a transition toward more electric vehicles that have far fewer components and are easier to manufacture,” Bernhard Mattes, the president of the German Association of the Automotive Industry, said in an interview in Berlin. “Therefore, we can expect less employment.”

Mattes, former head of Ford’s operations in Germany, quoted studies estimating that a shift to electric cars could cost 70,000 jobs in Germany by 2030. Some estimates are higher.

The effect of those cuts may be felt most acutely in communities like Öhringen, where the local economy revolves around small and midsize manufacturers, often serving the auto industry. Audi, Porsche and Daimler all have factories within a 40-mile radius.

Thilo Michler, the mayor of Öhringen, said the local economy was diverse enough to survive the closing of the Mahle plant. The city, with about 25,000 residents, is also the home of other midsize companies such as Huber Packaging, the world’s largest manufacturer of 5-liter beer kegs.

Unemployment is so low that most Mahle workers will probably find new jobs by the time the plant ceases operations by the end of 2020. But they will have trouble finding work that pays as well, and they may have to accept temporary contracts that offer little job security, said Rüdiger Bresien, an official of the IG Metall union who represents workers in the area.