Outgoing German Federal President Joachim Gauck used his final major speech to slam the rise of populism in Europe and the U.S. and claimed Germany’s democracy was under threat.

The 77-year-old German president, who will not seek another term, has said he fears for the internal security situation and new international pressures on Germany. “The liberal democracy and the political and normative project of the West are under attack,” he said, Die Welt reports.

According to Gauck, the main threats to Germany are external like the conflict in Ukraine and the actions of Russian President Vladimir Putin, the “challenge” of the election of Donald Trump in the U.S. and his views on NATO, and the global threat of Islamist terrorism which struck Germany multiple times in 2016.

“We need to do more to stabilise the European Union and to counter the internal and external attempts to divide it,” he said.

The outgoing president talked about the need for Europe to have an “efficient safeguarding of European external borders,” and said that future migrant crises will occur “without a regulated European immigrant policy”.

Last year President Gauck was heckled and labelled a “traitor” when he visited the state of Saxony in Eastern Germany as protesters called his inaction on the migrant crisis as “politically pathetic”.

The rise of the populist movements in Europe, particularly the anti-mass migration Alternative for Germany (AfD), reflect a growing polarisation of society according to Gauck. “A representative democracy should represent as many citizens as possible,” he said but added that “prejudices” shouldn’t be given the same aura of respect as issues.

He defended immigration and migrants in Germany claiming that “origin doesn’t count, attitude does”. He also noted that discussion of Islamism and radical Islamic intolerance for others shouldn’t be hidden, but should be spoken of in public so that an Islam that it adapts to German values of secularism and democracy.

In December, the president was wrong-footed after a Muslim girl refused to shake his hand as he visited a school that had been commended for helping migrants to integrate into German society.

The 77-year-old said he would have liked to stay on another term but due to his age had decided to step down. His likely successor will be current Foreign Minister Frank-Walter Steinmeier who is one of the most popular politicians in Germany and has called U.S. President-Elect Donald Trump a “hate preacher” in the past.