Get breaking news alerts and special reports. The news and stories that matter, delivered weekday mornings.

President Barack Obama called on Americans to unify in the face of what he characterized as "challenges to our democracy" in a sweeping farewell speech Tuesday night that served more as a call to action for the nation’s future than a recollection of successes past.

Speaking to a hometown audience estimated at nearly 20,000 people, Obama struggled to quiet a roaring crowd as he opened the speech by recounting how his political path began in Chicago.

"This is where I learned that change only happens when ordinary people get involved, get engaged, and come together to demand it," Obama said.

"After eight years as your President, I still believe that," he went on. "And it's not just my belief. It's the beating heart of our American idea — our bold experiment in self-government."

Related: Lester Holt Interviews President Obama Ahead of Final Address

But even as he rattled off a list of accomplishments from his eight years in office — expanded health care coverage under Obamacare, a record-breaking stretch of job growth and legal same-sex marriage nationwide — Obama acknowledged the limits, and even shortcomings, of his tenure as president.

Referencing the growth in income inequality on his watch, Obama declared that "for all the real progress we’ve made, we know it’s not enough.

Let our news meet your inbox. The news and stories that matters, delivered weekday mornings. This site is protected by recaptcha

"Our economy doesn’t work as well or grow as fast when a few prosper at the expense of a growing middle class."

He also lamented that despite his historic election as the nation's first black president, "race remains a potent and often divisive force in our society."

And though he promised a peaceful transfer of power to President-elect Donald Trump in the coming weeks, Obama seemed wary of the challenge the Trump Administration is expected to pose to his legacy.

The outgoing president used the bulk of his speech to offer an implicit rebuttal to many of the contentious themes, policies and developments that characterized the 2016 campaign and helped deliver Trump the White House last fall.

Trump drew fierce criticism during the campaign for controversial comments about minorities — warning that Mexico was sending "rapists" and "murderers" to the U.S., and asking African Americans "what do you have to lose?" by voting for Trump — that Democrats said were needlessly divisive.

In an implicit reference to such rhetoric, Obama warned that "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 also warned that "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."

And in a more direct challenge of some of Trump's signature policies — including his proposed ban on Muslim immigrants and his openness to using torture against terrorists — Obama continued:

"That’s why we’ve ended torture, worked to close Gitmo, and reform our laws governing surveillance to protect privacy and civil liberties. That’s why I reject discrimination against Muslim Americans."

Obama also warned against the increasing politicization of news and facts, in which Americans "retreat into our own bubbles ... surrounded by people who look like us and share the same political outlook and never challenge our assumptions."

"Without some common baseline of facts; without a willingness to admit new information, and concede that your opponent is making a fair point, and that science and reason matter, we’ll keep talking past each other, making common ground and compromise impossible," he said.

But even as Obama made his case against Trump, the Democrats' White House loss — partly the result of a drop in turnout among Obama's base voters from previous years — loomed over the speech.

His last request, to ensure the health of the nation's democracy, was for Americans to get involved.

"Our democracy is threatened whenever we take it for granted. All of us, regardless of party, should throw ourselves into the task of rebuilding our democratic institutions," he said.

And to uproarious applause from the audience, Obama closed his speech with an echo of the promise that helped deliver his improbable campaign an unexpected victory eight years ago: "Yes we can."

Calling it "that faith written into our founding documents; that idea whispered by slaves and abolitionists; that spirit sung by immigrants and homesteaders and those who marched for justice," Obama declared: "Yes we can."

He went on: "Yes we did. Yes we can."