"Democracy can buckle when we give in to fear. 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," Obama, 55, said in his address to the nation from his home town here.
The 55-year-old outgoing President lamented that despite his historic election as the nation's first black president in 2008, "race remains a potent and often divisive force in our society."
Obama's presidency will come to an end on January 20 when Republican Donald Trump would be sworn in as the 45th President of the US.
Obama promised a peaceful transfer of power to Trump in the coming weeks.
Without mentioning Trump, he used his speech to offer an implicit rebuttal to many of the contentious themes like temporary ban on Muslim immigration that characterised the 2016 presidential campaign.
Obama said he rejects discrimination against Muslim Americans, and drew cheers for saying they are "just as patriotic as we are".
"That's why we cannot withdraw from global fights - to expand democracy, and human rights, women's rights, and LGBT rights - no matter how imperfect our efforts, no matter how expedient ignoring such values may seem," he said.
Obama warned his countrymen that American democracy is threatened whenever they take it for granted.
"When trust in our institutions is low, we should reduce the corrosive influence of money in our politics, and insist on the principles of transparency and ethics in public service. When Congress is dysfunctional, we should draw our districts to encourage politicians to cater to common sense and not rigid extremes," he added.
He also warned economic divisions have intensified racial
To be serious about race, Obama said laws to fight discrimination in hiring, housing, education and criminal justice must be upheld - and "hearts must change."
"But we're not where we need to be. All of us have more work to do. After all, if every economic issue is framed as a struggle between a hardworking white middle class and undeserving minorities, then workers of all shades will be left fighting for scraps while the wealthy withdraw further into their private enclaves," Obama said.
"If we decline to invest in the children of immigrants, just because they don't look like us, we diminish the prospects of our own children - because those brown kids will represent a larger share of America's workforce," he warned.
For the fight against extremism and intolerance and sectarianism and chauvinism are of a piece with the fight against authoritarianism and nationalist aggression, he said adding if the "scope of freedom and respect for the rule of law shrinks around the world, the likelihood of war within and between nations increases, and our own freedoms will eventually be threatened".
He said no one can defeat America unless "we betray our Constitution and our principles in the fight".
After successful eight years of his presidency, Obama said he is leave this stage even more optimistic about this country than he was when started.
"By almost every measure, America is a better, stronger place" than it was eight years ago when he took office, he told thousands of supporters.
"This generation coming up - unselfish, altruistic, creative, patriotic - I've seen you in every corner of the country. You believe in a fair, just, inclusive America; you know that constant change has been America's hallmark, something not to fear but to embrace, and you are willing to carry this hard work of democracy forward. You'll soon outnumber any of us, and I believe as a result that the future is in good hands," Obama said.
He insisted that change results when "ordinary people get involved, get engaged and come together to demand it".
In his closing remarks he said he had one final request for Americans as president: "I am asking you to believe. Not in my ability to bring about change - but in yours.
