CHICAGO — President Obama, delivering a farewell address in the city that launched his political career, declared on Tuesday his continued confidence in the American experiment. But he warned, in the wake of a toxic presidential election, that economic inequity, racism and closed-mindedness threatened to shred the nation’s democratic fabric.
“We weaken those ties when we define some of us as more American than others,” Mr. Obama said, “when we write off the whole system as inevitably corrupt, and when we sit back and blame the leaders we elect without examining our own role in electing them.”
Speaking to a rapturous crowd that recalled the excitement of his path-breaking campaign in 2008, Mr. Obama said he believed even the deepest ideological divides could be bridged. His words were nevertheless etched with frustration — a blunt coda to a remarkable day that laid bare many of the racial crosscurrents in the country.
Mr. Obama pledged again to support his successor. But his speech was a thinly veiled rebuke of several of the positions Mr. Trump staked out during the campaign, from climate change and barring Muslims from entering the country to repealing his landmark health care law.
“If every economic issue is framed as a struggle between a hardworking white middle class and undeserving minorities,” Mr. Obama said, “then workers of all shades will be left fighting for scraps while the wealthy withdraw further into their private enclave.”
“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 work force,” he added.
In giving a farewell address, Mr. Obama invoked a privilege of presidents going back to George Washington. He staked his claim as the leader who steered the nation through the storms of the Great Recession to a growing economy and job market. He claimed credit for reducing the rate of uninsured Americans to record lows, while keeping a cap on health care costs.
In a pointed reference to Republicans determined to repeal the health care bill that was one of the signature accomplishments of his presidency, Mr. Obama said, “If anyone can put together a plan that is demonstrably better than the improvements we’ve made to our health care system — that covers as many people at less cost — I will publicly support it.”
There were also nostalgic moments, as well. He recalled the 2008 campaign that started him on his improbable journey to the White House. He thanked the army of volunteers and staff members who swept him into the Oval Office, ending with the iconic chant, “Yes, we can.” And reflecting on all they had accomplished, he added, “Yes, we did.”
“It has been the honor of my life to serve you,” Mr. Obama said. “I won’t stop; in fact, I will be right there with you, as a citizen, for all my remaining days.”
He drew some of the most thunderous applause of the night when he paid tribute to his wife, Michelle — “my best friend” — and Vice President Joseph R. Biden Jr. — “a brother.” As the crowd of 18,000 clapped and stamped their feet, Mr. Obama dabbed his eyes.
Afterward, Mrs. Obama and her elder daughter, Malia, appeared onstage with the president, along with Mr. Biden and his wife, Jill. The Obamas’ younger daughter, Sasha, stayed in Washington because she has an exam in school on Wednesday morning, the White House said.
But Mr. Obama clearly wanted to use his last major turn on the national stage to send a message. Americans, he said, should not take their democracy for granted. Lamenting the perennially low voter turnout rates, Mr. Obama urged people to become involved. “If you’re tired of arguing with strangers on the internet,” he said, “try to talk with one in real life.”
“America is not a fragile thing,” the president said. “But the gains of our long journey to freedom are not assured.”
The White House had meticulously planned this event, from the location to the tone and cadence of the speech, which clearly reached for the oratorical heights of his best-remembered addresses.
The president was still rewriting his remarks on Tuesday afternoon, one of his aides said, after being up very late Monday night scrawling edits on what was then already the fourth draft.
Mr. Obama’s chief speechwriter, Cody Keenan, pored over previous farewell addresses for inspiration. George Washington used the occasion to disclose he would not run for a third term and warned Americans to steer clear of foreign entanglements in Europe, while Dwight D. Eisenhower warned of the influence of the “military-industrial complex.”
Mr. Obama’s message recalled his final State of the Union address last year, as well as speeches he gave in Springfield, Ill.; at the commencement ceremonies at Howard University and Rutgers University; and during the Democratic National Convention.
Dozens of alumni from the White House and Mr. Obama’s political operation converged on Chicago to cheer their boss. With parties all over town, the atmosphere felt like a wistful version of 2012, or even more so, of 2008, when Mr. Obama’s election drew a quarter-million people to a jubilant victory celebration in nearby Grant Park.
There was, however, an undeniable tinge of sadness to Mr. Obama’s leave-taking — the dread among many in this crowd that his legacy will be undone by Mr. Trump, and the disappointment that, for all his political gifts, he was unable to hand over his office to his chosen successor, Hillary Clinton.
“Beers and tears,” said Ben LaBolt, who served as the national press secretary for Mr. Obama’s re-election campaign.
Many said they had waited hours in the cold to get tickets, like Ja-mese McGee, an elementary school teacher from the Chicago suburb Country Club Hills.
Those hours had a purpose. She wanted to demonstrate to her students that seeing Mr. Obama was worth the wait. “Better than waiting to shop on Black Friday. Better than waiting in line for gym shoes,” she said.
But Ms. McGee was troubled by Mr. Trump’s inauguration, and the damage it could do to Mr. Obama’s legacy. “There’s so much to say about him,” she said. “He maintained class, he maintained dignity. Honestly, I don’t want him to leave, but I’m sure it will be a load off his shoulders.”
Alvin Love, a Baptist minister, walked through the crowd holding the hand of his 6-year-old granddaughter, Bayleigh Love, who wore a red sequined party dress.
He and Mr. Obama go back 30 years, when the president was a young community organizer on the South Side. “It’s mixed emotions for me,” he said. “I’m sad to see it come to an end, but proud and happy to see the work that he’s done.”
Mr. Love said he believed Mr. Obama’s work could be sustained, even with the advent of a Trump presidency. “Any time right is done, it will sooner or later stand up again.”