Barack Obama will step down next week when President-elect Donald Trump takes office
President Barack Obama has given his farewell speech in Chicago, where he celebrated the achievements of the past and made warnings for the future.
In a packed convention centre, not far from where he made his victory speech eight years earlier, he told thousands of well-wishers that the work of democracy has always been hard - and can often feel like for every two steps taken forward, one step is taken back.
But to loud cheers from his supporters, he outlined some of his administration's biggest triumphs - including job creation, thawing relations with Cuba, the death of 9/11 mastermind Osama bin Laden, marriage equality and the right to health insurance for another 20 million Americans.
Mr Obama said: "If I told you all that we would do all that eight years ago ... you might have said our sights were set a little too high. But that's what we did."
In the wake of Donald Trump's election as 45th President of the United States, Mr Obama acknowledged that the nation's progress had been "uneven" - but said the country "strives for forward motion and a constant widening of our founding creed to embrace all, not just some".
The outgoing President said he had pledged to Mr Trump that his administration would ensure the smoothest possible transition of power, and said the nation's politics needed to reflect "the decency" of the American people.
Mr Obama warned that race remains a divisive force in American society, and everyone has more work to do in upholding laws against discrimination in education and the criminal justice system.
He also stressed that the children of tomorrow will be dealing with regular environmental disasters if the existence of climate change is denied rather than confronted.
The President vowed that the fight against terrorism would continue, saying: "IS will be destroyed and no one who threatens America will ever be safe."
However, in a warning shot to Mr Trump, he said he rejected the discrimination of Muslim-Americans "who are just as patriotic as we are".
Mr Obama wiped his eyes as he thanked his wife Michelle for her support throughout his presidency, and said selecting Joe Biden as his running mate was the first and best choice he ever made.
He also expressed his gratitude to his daughters Sasha and Malia for the sacrifices they made in making his political dreams a reality, and said they "wore the burden of years in the spotlight so easily".
Malia sat next to her mother Michelle during the speech in Chicago, but younger daughter Sasha did not attend as she had an exam in Washington the following morning.
Mr Obama is leaving office as a relatively popular president - with opinion polls giving him a favourability rating among voters of between 55% and 57%.
But Americans remain deeply divided about his legacy.
Fewer than half say they are better off than they were when the Democrat entered the White House in 2009 - and two-thirds of Americans believe he was unable to keep his election promises.