US president Barack Obama has made an emotional farewell speech that sought to comfort and encourage a country on edge over economic changes, persistent security threats and the election of Donald Trump.
Mr Obama's valedictory speech in his home city of Chicago was a public meditation on the trials and triumphs, promises kept and promises broken that made up his eight years in the White House.
Arguing his faith in America had been confirmed, he said he ended his tenure inspired by its "boundless capacity" for reinvention, declaring: "The future should be ours."
His delivery was forceful for the most part, but by the end he was wiping away tears as the crowd embraced him one last time. He and his wife Michelle hugged former aides and other audience members long after the speech ended.
Reflecting on the corrosive recent political campaign, Mr Obama, 55, said America's great potential "will be realised only if our democracy works. Only if our politics reflects the decency of our people. Only if all of us, regardless of our party affiliation or particular interest, help restore the sense of common purpose that we so badly need right now".
He made only passing reference to Republican Donald Trump, who will replace him in just 10 days.
He said he pledged to Mr Trump that his administration would "ensure the smoothest possible transition" just as his predecessor George Bush did for him, and the nation's politics needed to reflect "the decency" of the American people.
But when Mr Obama noted the imminence of that change and the crowd began booing, he responded, "No, no, no, no, no", saying one of the nation's great strengths "is the peaceful transfer of power from one president to the next".
The president acknowledged "stark inequality" was corrosive to America's democratic principles, in a nod to the economic uncertainty that helped Mr Trump win the White House.
He said too many inner city and rural families had been left behind, convinced the "game is fixed against them" and the government serves only powerful interests.
Protecting America's way of life, he said, was the job of citizens as well as the military, adding: "Democracy can buckle when we give in to fear."
And to cheers from the crowd, Mr Obama, referring to Donald Trump's calls for a temporary ban on Muslim immigration, said he rejected discrimination against Muslim Americans "just as patriotic as we are".
Earlier, as the crowd chanted "Four more years", he simply smiled and said: "I can't do that."
Nevertheless, during his speech Mr Obama carried out what seemed like a point-by-point rebuttal of Mr Trump's vision for America.
He lamented politicians who question climate change and warned about the threat to US democracy posed by purposely deceptive fake "news" and a growing tendency of Americans to listen only to information that confirmed what they already believed.
Get out of your "bubbles", said Mr Obama who rose to a prominence with a message of unity, challenging divisions of red states and blue states.
He also revived a call to activism that marked his first presidential campaign, telling Americans to stay engaged in politics, saying: "If you're tired of arguing with strangers on the internet, try to talk with one in real life."
Mr Obama also paid tribute to the sacrifices made by his wife and his daughters, who were young girls when they entered the big white home in Pennsylvania Avenue and now leave as young women.
Unexpectedly absent was the Obamas' younger daughter, Sasha, who had been expected to join her sister Malia at the speech. The White House did not explain the absence.
Mr Obama praised his wife for taking on her role "with grace and grit and style and good humour" and for making the White House "a place that belongs to everybody".
Soon Mr Obama and his family will exit the national stage, to be replaced by Mr Trump, a man who Mr Obama had stridently argued posed a dire threat to the nation's future.
His near-apocalyptic warnings throughout the campaign cast a continuing shadow over his post-election efforts to reassure Americans anxious about the future.
Indeed, much of what Mr Obama accomplished over the past eight years - from health care overhaul and environmental regulations to his nuclear deal with Iran - could potentially be upended by Mr Trump, so even as the president seeks to define what his tenure meant for America, his legacy remains in question.
Even as Mr 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 centre 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 Mr Trump.
Steeped in nostalgia, Mr Obama's return to Chicago was less a triumphant homecoming and more a bitter-sweet reunion bringing together Obama loyalists and loyal staffers, many of whom have long since left his 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 Mr Obama's presidency.
Seeking inspiration, Mr Obama's speechwriters spent weeks poring over his other momentous speeches, including his 2004 keynote at the Democratic National Convention and his 2008 speech after losing the New Hampshire primary to Hillary Clinton.
They also revisited his 2015 address in Selma, Alabama, that both honoured America's exceptionalism and acknowledged its painful history on civil rights.
After returning to Washington, Mr Obama will have less than two weeks before he accompanies Mr Trump in the presidential limousine to the Capitol for the new president's swearing-in.
He then plans to take some time off, write a book, and immerse himself in a Democratic re-districting campaign.