Barack Obama will deliver his final speech as president beginning at 9 p.m. ET. Watch PBS NewsHour’s livestream of the speech above.

CHICAGO — President Barack Obama bid farewell to the nation Tuesday in an emotional speech that sought to comfort a country on edge over rapid economic changes, persistent security threats and the election of Donald Trump.

Forceful at times and tearful at others, Obama’s valedictory speech in his hometown of Chicago was a public meditation on the many trials the U.S. faces as Obama takes his exit. For the challenges that are new, Obama offered his vision for how to surmount them, and for the persistent problems he was unable to overcome, he offered optimism that others, eventually, will.

“Yes, our progress has been uneven,” Obama told a crowd of some 18,000. “The work of democracy has always been hard, contentious and sometimes bloody. For every two steps forward, it often feels we take one step back.”

Yet Obama argued his faith in America had only been strengthened by what he’s witnessed the past eight years, and he declared: “The future should be ours.”

Brushing away tears with a handkerchief, Obama paid tribute to the sacrifices made by his wife — and by his daughters, who were young girls when they entered the big white home on Pennsylvania Avenue and leave as young women. He praised first lady Michelle Obama for taking on her role “with grace and grit and style and good humor” and for making the White House “a place that belongs to everybody.”

Video by PBS NewsHour

Soon Obama and his family will exit the national stage, to be replaced by Trump, a man Obama had stridently argued poses a dire threat to the nation’s future. His near-apocalyptic warnings throughout the campaign have cast a continuing shadow over his post-election efforts to reassure Americans anxious about the future.

Indeed, much of what Obama accomplished during his two terms — from health care overhaul and environmental regulations to his nuclear deal with Iran — could potentially be upended by Trump. So even as Obama seeks to define what his presidency meant for America, his legacy remains in question.

Even as Obama said farewell — in a televised speech of just under an hour — the anxiety felt by many Americans about the future was palpable, and not only in the Chicago convention center where he stood in front of a giant presidential seal. The political world was reeling from new revelations about an unsubstantiated report that Russia had compromising personal and financial information about Trump.

Video by PBS NewsHour

Obama made only passing reference to the next president. When he noted he would soon be replaced by the Republican, his crowd began to boo.

“No, no, no, no, no,” Obama said. One of the nation’s great strengths, he said, “is the peaceful transfer of power from one president to the next.”

Earlier, as the crowd of thousands chanted, “Four more years,” he simply smiled and said, “I can’t do that.”

Still, Obama offered what seemed like a point-by-point rebuttal of Trump’s vision for America.

He pushed back on the isolationist sentiments inherent in Trump’s trade policies. He decried discrimination against Muslim Americans and lamented politicians who question climate change. And he warned about the pernicious threat to U.S. democracy posed by purposely deceptive fake “news” and a growing tendency of Americans to listen only to information that confirms what they already believe.

Get out of your “bubbles,” said the politician who rose to a prominence with a message of unity, challenging divisions of red states and blue states. Obama also revived a call to activism that marked his first presidential campaign, telling Americans to stay engaged in politics.

“If you’re tired of arguing with strangers on the internet,” Obama said pointedly, “try to talk with one in real life.”

With Democrats still straining to make sense of their devastating election losses, Obama tried to offer a path forward. He called for empathy for the struggles of all Americans — from minorities, refugees and transgender people to middle-aged white men whose sense of economic security has been upended in recent years.

Paying tribute to his place as America’s first black president, Obama acknowledged there were hopes after his 2008 election for a post-racial America.

“Such a vision, however well-intended, was never realistic,” Obama said, though he insisted race relations are better now than a few decades ago.

Video by PBS NewsHour

The former community organizer closed out his speech by reviving his campaign chant, “Yes we can.” To that, he added for the first time, “Yes we did.”

He staunchly defended the power of activists to make a difference — the driving factor behind Obama’s optimism in the face of so much anxiety, he said. Though the coalition of young Americans and minorities who twice got Obama elected wasn’t enough to elect Democrat Hillary Clinton to replace him, Obama suggested their day was still ahead.

“You’ll soon outnumber any of us, and I believe as a result that the future is in good hands,” he said.

Steeped in nostalgia, Obama’s return to Chicago was less a triumphant homecoming than a bittersweet reunion bringing together loyalists and staffers, many of whom have long since left Obama’s service, moved on to new careers and started families. They came from across the country — some on Air Force One, others on their own — to be present for the last major moment of Obama’s presidency.

Video by PBS NewsHour

Unexpectedly absent was Obama’s younger daughter, Sasha, who had been expected to join sister Malia at the speech. The White House said Sasha stayed in Washington due to a school exam Wednesday morning.

After returning to Washington, he will have less than two weeks before he accompanies Trump in the presidential limousine to the Capitol for the new president’s swearing-in. After nearly a decade in the spotlight, Obama will become a private citizen, an elder statesman at 55. He plans to take some time off, write a book — and immerse himself in a Democratic redistricting campaign.

Lederman reported from Washington. Associated Press writers Ken Thomas and Calvin Woodward in Washington contributed to this report.

READ MORE: ‘I won’t stop serving you,’ President Obama tells crowd in farewell address