CHICAGO — President Obama delivered a nostalgic and hopeful farewell address to the nation on Tuesday evening, but warned both the divided country he led for eight years and his successor not to shrink from the challenges of economic inequality, racial strife, political isolation and voter apathy that still threaten its ideal of democracy.
Mr. Obama returned to the city that nurtured his political career and his improbable journey from Hyde Park to Pennsylvania Avenue, just 10 days before he will leave the White House to Donald J. Trump. In his final speech to the nation, the president expressed his belief that even the deepest ideological divides can be bridged by an active, engaged populace.
“After eight years as your president, I still believe that,” Mr. Obama told a large crowd at McCormick Place, the cavernous lakeside convention center where he thanked supporters after his re-election in 2012. “And it’s not just my belief. It’s the beating heart of our American idea — our bold experiment in self-government.”
The podcast that makes sense of the most delirious stretch of the 2016 campaign.
Tearing up as he concluded the final speech of a remarkable political career, Mr. Obama thanked his wife, his daughters, his vice president (“the scrappy kid from Scranton”) and the army of supporters who helped sweep the first African-American into the White House.
“I won’t stop; in fact, I will be right there with you, as a citizen, for all my days that remain,” Mr. Obama pledged, fighting back emotion as audience members rose to their feet. He asked them to believe, as they did during his first campaign. “Yes, we can. Yes, we did. Yes, we can.”
But a president who rode an exhortation of hope and change to the Oval Office delivered a final speech to the country built around the need to confront a changing world and nation.
Mr. Obama urged the country to deal with the persistent problems that undermine the equality, diversity and unity that he sought to achieve during his tenure. He said economic inequality would continue to cause “disaffection and division” and warned that race would remain a potent force dividing the nation unless discrimination is attacked and eliminated.
“But laws alone won’t be enough. Hearts must change,” he told the crowd. “When minority groups voice discontent, they’re not just engaging in reverse racism or practicing political correctness; that when they wage peaceful protest, they’re not demanding special treatment, but the equal treatment our founders promised.”
The president said that a splintered news media threatened democracy by allowing people to retreat into their own bubbles of knowledge, everyone certain of a different set of facts. “We become so secure in our bubbles that we accept only information, whether true or not, that fits our opinions, instead of basing our opinions on the evidence that’s out there,” he said.
And, the president said, the country’s democratic order is threatened by a sense of apathy among the many Americans who do not vote or participate in civic life. He urged members of both political parties to work to restore trust in society’s institutions in ways that will attract more people to become involved in the country’s fate.
“If something needs fixing, lace up your shoes and do some organizing,” Mr. Obama, a onetime community organizer, told the crowd. “If you’re disappointed by your elected officials, grab a clipboard, get some signatures, and run for office yourself. Show up. Dive in. Persevere. Sometimes you’ll win. Sometimes you’ll lose.”
But, he added: “More often than not, your faith in America — and in Americans — will be confirmed.”
Eight years ago, Mr. Obama basked in the glow of his history-making victory that drew nearly a quarter-million people to a jubilant celebration in the city’s nearby Grant Park. On Tuesday night, visibly older and chastened by years of political battles in Washington, Mr. Obama returned to his adopted hometown to bring his tenure to an end.
“You are the best supporters and organizers anyone could hope for, and I will forever be grateful. Because yes, you changed the world,” Mr. Obama said. “I leave this stage tonight even more optimistic about this country than I was when we started.”
But that expression of hope was tempered by the reality playing out in the nation’s capital: Mr. Trump has promised to unwind Mr. Obama’s legacy, erasing the president’s disciplined and professorial approach to governing with a noisy, chaotic style of leadership. Even as Mr. Obama took the stage, another controversy dogged Mr. Trump even before his inauguration as unverified allegations about his personal behavior emerged in news reports.
Mr. Obama said he had committed to ensuring Mr. Trump “the smoothest possible transition,” drawing boos from a crowd clearly not ready to see that happen; at one point, they began chanting, “Four more years.” Mr. Obama dismissed them quickly, though. “I can’t do that,” he said.
In parts of the speech, Mr. Obama appeared to be talking to Mr. Trump as much as the rest of America, warning him of the dangers of continuing to stoke the divisions that helped Republicans defeat Hillary Clinton in the presidential campaign.
“That’s why I reject discrimination against Muslim Americans,” Mr. Obama said to huge cheers from the adoring crowd. “That’s why we cannot withdraw from global fights — to expand democracy, and human rights, women’s rights, and L.G.B.T. rights — no matter how imperfect our efforts, no matter how expedient ignoring such values may seem.”
To a successor who has often questioned the reality of climate change, Mr. Obama seemed to say: Be careful.
“We can and should argue about the best approach to the problem,” he said. “But to simply deny the problem not only betrays future generations; it betrays the essential spirit of innovation and practical problem-solving that guided our founders.”
For many Chicago residents, who embrace Mr. Obama as one of their own, the president’s speech was a coda to a political career that spoke as much to their own evolution as a community as it did to how the nation has changed over his eight years in office.
The White House had meticulously planned the event, from the location to the tone and cadence of the speech. Mr. Obama was still rewriting the speech on Tuesday afternoon, one of his aides said, after being up late Monday night scrawling edits on what at that point was the fourth draft.
Dozens of alumni from the White House and Mr. Obama’s political operation converged on Chicago to witness their former boss’s last major turn on the national stage, attending parties and receptions all over town. “Beers and tears,” said Ben LaBolt, the former national press secretary for Mr. Obama’s re-election campaign.