The Greens in Germany could hardly believe it. Leading party members were bouncing up and down when the public broadcasters sent the first, still uncertain results on the evening of the European Union elections. The green column rose to 20% and above, close to the black column of Angela Merkel’s Christian Democrats, which ended up with 22.6%. Party manager Michael Kellner was beaming as the numbers came in.

Over the course of the evening it became clear that the Green party had nearly doubled its seats in the European parliament and had overtaken the Social Democrats, the former “people’s party”. A historic victory for us, a historic disaster for them.

All over Europe, the Green parties enjoyed modest gains, but nowhere did they gain so many votes as in Germany. Last week they even came out on top in one national opinion poll, overtaking Merkel’s conservatives for the first time.

For decades denounced as eco-nerds and tree-huggers, the Greens now incarnate the zeitgeist perfectly

The success of the German Greens is surely linked to the weakness of the governing coalition of Christian and Social Democrats. Both parties struggle with image problems, partly connected to their leadership. The head of the Social Democrats, Andrea Nahles, has just stepped down following the party’s disastrous showing in the European elections. She was the party’s 10th leader in 15 years.

But the Green wave cannot be explained away by its rivals’ failings. For decades denounced as eco-nerds and tree-huggers, the Greens have now conquered the progressive middle class and captured the zeitgeist. Green issues such as environmental protection, climate emergency and clean energy are mainstream. Vegetarianism and organic food are popular lifestyle choices. An extremely hot summer and the diesel scandal caused by German carmaker Volkswagen made even more people wonder whether the philosophy of unlimited growth and endless use of natural resources should be questioned.

All across Europe, pupils are skipping lessons and demonstrating for their future – and the Greens are riding the wave while other political parties are simply swimming in unknown waters. A third of German voters under the age of 30 voted Green in the European elections. By comparison, 13% of the same age group voted for the Christian Democrats and 10% for the Social Democrats. It isn’t hard to predict which party will grow in the future and which parties could shrink.

But there’s another reason the Greens have gained popularity. After the summer of 2015, when hundreds of thousands of refugees migrated to Germany, the new far-right party, Alternative für Deutschland (AfD) grew stronger, fostering resentment and fear against migrants. Although some Green politicians pledged to help deportations, the party overall managed to stand up for a liberal migration policy and for being uncompromisingly pro-European. They are the antithesis of the growing nationalism, EU scepticism and anti-migration sentiment that is that is prevalent on the continent. So in a society that is deeply divided, the success of the Greens and the growth of the far right are two sides of the same coin.

Young people to advise UK on hitting net zero emissions by 2050 Read more

The AfD won 11% of the votes in the European election. Compared with the national election in 2017, the party lost a few percent – and compared with Marine Le Pen’s National Rally in France, or Matteo Salvini’s League in Italy, its results were moderate.

But in the eastern German states, Saxony and Brandenburg, the AfD became the dominant party – apart from in Leipzig, the biggest town in Saxony, where the Greens became the strongest party for the first time in 30 years.

Twenty kilometres away from Leipzig, in the neat little village of Kieritzsch, one in two voters chose the AfD. It may have something to do with Kieritzsch being situated on the edge of an opencast mine. By 2038, coal-fired power production is meant to end in Germany and the mines will be shut down. The Greens want to speed up this process. The AfD, on the other hand, denies that climate change is manmade, and would keep the plant.

Because of their successes in big cities, the Greens are actually contributing to deeper divisions between urban and sparsely populated areas, between young and old, and between those who embrace globalisation and those who fear it.

So if they want to reconcile the different groups, the Greens have to focus on social issues as well, such as how to pay, and who will pay, for the transition from dirty to clean energy; from fossil fuel-powered cars to electric vehicles. Will it be chiefly the people in areas that today depend on coal plants and mines, or the owners of diesel cars?

When Emmanuel Macron in France proclaimed a tax on fuel he faced a nationwide movement of gilets jaunes. His experience shows that green and social questions have to be looked at together. So the Greens have to focus harder on social politics. A few weeks ago they presented their model of a basic income for all families with children. To achieve this they would have to form an alliance with the Social Democrats and the leftwing Die Linke. The Greens feel strong enough to ignore their approaches at the moment and leave all options open. That won’t work in the long run.

If the Greens fail to reconcile social and environmental matters, they risk being seen as part of a complacent elite, and will be fought by those who don’t feel represented. A fight like this, that leaves the political system as well as society wrecked, can be seen in Britain. Beware.

• Anna Lehmann is an editor on the Berlin-based daily newspaper Die Tageszeitung