In his final speech as US president after eight years in power, Barack Obama admitted that his tenure has been “hard, contentious and sometimes bloody,” but still tried to strike a positive note and insisted that he leaves the White House even more optimistic than when he entered.

“Democracy can buckle when we give in to fear,” Obama said at his farewell speech in Chicago, the city where he began his political career. “So just as we, as citizens, must remain vigilant against external aggression, we must guard against a weakening of the values that make us who we are.”

In 10 days, Obama will hand over the presidency to President-elect Donald Trump, amid allegations that the 2016 elections were influenced by the efforts of Russian intelligence agencies. Obama acknowledged that the election has not gone as expected and brought up tensions within American democracy that could erupt.

“For too many of us, it’s become safer to retreat into our own bubbles, whether in our neighborhoods or college campuses or places of worship or our social media feeds, surrounded by people who look like us and share the same political outlook and never challenge our assumptions,” Obama said.”The rise of naked partisanship, increasing economic and regional stratification, the splintering of our media into a channel for every taste – all this makes this great sorting seem natural, even inevitable.”

The outgoing president called on Americans to be vigilant, but not afraid and to ensure that political dialogue doesn’t become so corrosive “that people of good character are turned off from public service; so coarse with rancour that Americans with whom we disagree are not just misguided, but somehow malevolent.”

He concluded by insisting that he is more optimistic than when he took over the presidency, saying that the generation coming up believes in a fair, just, inclusive America and will soon outnumber everyone else.

“For now, whether you’re young or young at heart, I do have one final ask of you as your President – the same thing I asked when you took a chance on me eight years ago,” Obama said. “I am asking you to believe. Not in my ability to bring about change – but in yours.”