Germany’s Green Party entered the government in 2021 with the best election showing of its history, establishing itself for the first time as a true mainstream party with the potential of one day even yielding a chancellor.

It won five cabinet positions in the three-party coalition, including the powerful economy and foreign ministries. It seemed to have a strong mandate to advance the country’s economic transition toward a greener future.

What a difference two years make. And a Russian invasion of Ukraine. And rising energy costs. And a host of missteps that some even within the party concede has stalled the Greens’ momentum.

Today the Greens are widely viewed as a drag on the government of the Social Democratic chancellor, Olaf Scholz, which one poll gave a mere 19 percent approval rating. The Greens have drawn withering attacks from even their own coalition partners. To their opponents, the Greens have overreached on their agenda and become the face of an out-of-touch environmental elitism that has alienated many voters, sending droves to the far right.

In important state elections this month, all the parties in the governing coalition took a beating, but the Green Party was singled out for special attack as populists and the far right surged.

“They’ve made the Greens public enemy No. 1,” said Sudha David-Wilp, director of the Berlin office of the German Marshall Fund, a research institute.

The reversal of fortunes for the Greens is the story of a party that has long struggled to transcend its roots as a niche, environmentalist party to become a more pragmatic political force capable of broader appeal to lead the country.

Formed in 1980, the Greens built their base by taking a relatively hard line on environmental issues and climate change. Previously their pinnacle of power was as a coalition partner in the government of Chancellor Gerhard Schröder from 1998 to 2005.

But in Mr. Scholz’s government, which also includes the pro-business Free Democrats, the Green presence has been weightier, and the party’s stumble raises questions about whether the German economy, Europe’s biggest, can make progress toward its ambitious climate targets.

The Greens hold the high-profile portfolio of foreign minister, under Annalena Baerbock, 42. They also have the important ministry for economic affairs and climate action, under Robert Habeck.

Mr. Habeck, 54, who has a doctorate in literary sciences and has written novels, political books and stories for young adults, was once one of the country’s most popular politicians. But he has seen his standing fall along with his party’s. Today the Greens are polling at about 14 percent, around what they got in the last national election but well below the stronger ratings of their early months in power.

Mr. Habeck declined a request for an interview. But in remarks to the German media, he has conceded he misjudged the mood of crisis fatigue in the country after a winter of coping with surging energy prices in the wake of Russia’s invasion of Ukraine.

“The feeling of great time pressure has dissipated; instead of the fear of a loss of gas supplies, other concerns have come to the fore,” he told the newspaper Frankfurter Allgemeine Zeitung. “This change wasn’t so clear to me at first, and maybe that’s why I didn’t do everything right in the situation.”

Initially, Mr. Habeck and the Greens enjoyed significant successes, urging a hawkish stance against Russia. They were instrumental in passing a popular 49-euro, all-you-can ride ticket to encourage people to take public transportation and in pushing through changes to encourage investment in green energy.

They also skillfully helped navigate Germany away from its dependence on Russian natural gas. The government restricted temperatures in public buildings to save energy. It reopened coal plants. And it rapidly constructed terminals so Germany could import gas from sources other than Russia.

Those steps were welcomed by Germans as pragmatic and somewhat unexpected from a party traditionally committed in the long run to phasing out fossil fuels.

“The Greens were on the way to being a party of the political middle,” said Manfred Güllner, director of the Berlin-based Forsa Institute, a polling firm. “Now the Greens have landed back to exactly where they were for a long time: a small party that caters to its followers that is far removed from being a major party.”

Indeed, what was pragmatic to many Germans was seen as a betrayal of the party’s long-cherished principles by many of the Greens’ rank and file.

As the Greens have pivoted back to their traditional agenda, the party has bumped up against the limits of what many Germans are willing to sacrifice at a time of economic insecurity stemming from the war in Ukraine, higher inflation and the lingering effects of the Covid pandemic.

The shine started to come off, Mr. Güllner said, when the Greens fought against keeping nuclear power plants running past a deadline for shuttering them that had been previously agreed on. But Exhibit A in voter disillusionment was a bill that Mr. Habeck promoted requiring that newly installed home heating systems run on at least 65 percent renewable energy starting next year.

The mainstream conservative opposition, the Christian Democrats, attacked the heating law, or Heizungsgesetz, as climate policy “with a crowbar.” The tabloid Bild called it “Habecks Heiz-Hammer,” or “Habeck’s heating hammer.” The Greens were easily caricatured as a party oblivious to people’s struggles.

“They squandered a lot of their success because they seemed detached from ordinary people,” said Markus Ziener, a visiting fellow at the German Marshall Fund. “Instead of setting incentives, they were seen as telling people what’s right and what’s wrong, as wanting to lecture people.”

Experts said the law, which was passed in weakened form in September, has helped fuel the growing popularity of the far-right Alternative for Germany party, or AfD, which is polling at more than 20 percent, around the highest in its history.

Like other far-right parties across Europe, the AfD has added opposition to climate policies to its agenda, alongside issues like immigration, seeking to capitalize on the economic anxieties of working people.

“What happened with the Heizungsgezetz was all of a sudden literally the Greens were knocking on people’s doors, asking, ‘Show me your heating, and it has to change,’” said Andrea Römmele, a political scientist at the Hertie School in Berlin. “It was too fast.”

Omid Nouripour, one of the Greens’ co-chairs, said that the party could cope with the recent setbacks and that it had come a long way from the years when it polled single digits and seemed to be stuck in permanent opposition.

The troubles should not make the Greens pause, he insisted. “We can’t slow down,” he said in an interview. “It’s always been a tough game.”

Other Greens, too, said they did not consider the recent experience a crisis, though they acknowledged the need to reach beyond the party’s traditional voters, who tend to be better educated and financially comfortable.

“The key thing is going to be — the challenging thing, but also the beautiful thing — is to convince people who don’t yet think the way we do,” said Katrin Göring-Eckardt, a longtime leader in the party from eastern Germany who is now a vice president of Parliament.

Some say the Greens can still recover. Bernd Ulrich, a journalist with the newspaper Die Zeit who is writing a book on green politics, said that Mr. Habeck, in particular, would be key to whether the party could restore its stature.

“It’s the deepest crisis in the Greens’ history,” he said. “Robert Habeck is the most talented politician in Germany by far. He has become a scapegoat. But he can get them past it.”