Former president Barack Obama has said young leaders in Europe need to foster reasoned debate online to prevent politics going “in a negative direction”.

At a town hall meeting in Berlin, Mr Obama warned activists that action was needed to control social media and create “pockets of sanity and kindness” on the internet.

“I do believe part of what’s driving our politics in a negative direction is the information overload that is coming in through social media,” he said. “We are collectively, all of us, going to have to find ways in which we improve the conversation on the internet and social media.”

He added that the challenge will only become more difficult with widespread use of artificial intelligence.

“If you think fake news is bad now, what you’re going to start seeing is the ability to duplicate people’s speech so distinguishing what’s true and what’s not is going to become even more difficult,” he said.

Barack Obama's best moments in the White House Show all 11 1 /11 Barack Obama's best moments in the White House Barack Obama's best moments in the White House May 19, 2009 “The President was leaving the State Floor after an event and found Sasha in the elevator ready to head upstairs to the private residence. He decided to ride upstairs with her before returning to the Oval Office,” Peter Souza Barack Obama's best moments in the White House Oct. 26, 2012 President Barack Obama pretends to be caught in Spider-Man's web as he greets the son of a White House staffer in the Outer Oval Office Peter Souza Barack Obama's best moments in the White House “A National Security staffer, Carlton Philadelphia, brought his family to the Oval Office for a farewell photo with President Obama. Carlton’s son, Jacob, softly told the President he had just gotten a haircut like President Obama, and asked if he could feel the President’s head to see if it felt the same as his.” Peter Souza Barack Obama's best moments in the White House March 21, 2010 The President, Vice President and senior staff applaud after watching on television the House vote on H.R. 4872 for health care reform, in the Roosevelt Room of the White House Peter Souza Barack Obama's best moments in the White House Dec. 3, 2009 President Barack Obama fist-bumps custodian Lawrence Lipscomb in the Eisenhower Executive Office Building following the opening session of the White House Forum on Jobs and Economic Growth Peter Souza Barack Obama's best moments in the White House Sept. 22, 2015 "The Obama family and Biden family greet Pope Francis as he arrives in the United States for the first time at Joint Base Andrews," Sept. 22, 2015. Peter Souza Barack Obama's best moments in the White House Feb. 21, 2014 President Barack Obama and Vice President Joe Biden participate in a "Let's Move!" video taping on the Colonnade of the White House, Feb. 21, 2014 Peter Souza Barack Obama's best moments in the White House Feb. 18, 2016 President Barack Obama watches First Lady Michelle Obama dance with 106-Year-Old Virginia McLaurin in the Blue Room of the White House prior to a reception celebrating African American History Month, Feb. 18, 2016 Peter Souza Barack Obama's best moments in the White House Jan. 21, 2013 "The President and First Lady wave to supporters as they ride in the inaugural parade. I had asked the President if I could ride in the presidential limousine and the President joked, 'But Michelle and I were planning to make out," Jan. 21, 2013. Peter Souza Barack Obama's best moments in the White House Barack Obama and former First Lady Michelle Obama share a private moment in a freight elevator at an Inaugural Ball, January 2009 all pics: Pete Souza Barack Obama's best moments in the White House Barack Obama rests his hand on the bible that President Lincoln used for his swear-in, being held by his wife Michelle Obama as he is sworn in as the 44th President of the United States of America Rex

However, he rejected the idea of censoring social media, citing China and Russia as examples which he said show the “potential for abuse” with internet censorship.

Although the former president did not mention his successor Donald Trump explicitly, the contrast between the two leaders was clear.

Mr Obama spoke out in favour of tackling inequality and the “existential challenge” presented by climate change.

He also warned “nationalism, particularly from the far right, has re-emerged”, adding that despite Europe’s social achievements and decades of peace, “we know that powerful forces are working to reverse many of these trends”.

The town hall meeting was organised by the Obama Foundation, which aims to inspire participation in politics.

Mr Obama called on young people to play an active role in politics and not allow older generations to decide the direction of their country.

“When we hear that young people aren’t voting or participating, we say to them, you would not let your grandfather or grandmother decide what clothes you wear or what music you listen to, so why would you let them decide the world you’re going to live in?” he said.

“If we can get young leaders like you to begin to work together… to work in concert and teach and learn from each other, then you will change the world.”

Mr Obama also met with German chancellor Angela Merkel during his visit to Germany, where they reportedly discussed transatlantic relations.

Ms Merkel’s relationship with the US has become tense under the Trump administration, with the current president repeatedly criticising Germany’s contribution to military spending.