President Barack Obama has called on Americans to defend their democracy in his farewell speech in Chicago.
“By almost every measure, America is a better, stronger place” than it was eight years ago, he told thousands of supporters.
But he warned “democracy is threatened whenever we take it for granted”.
He implored Americans of all backgrounds to consider things from each other’s point of view, saying “we have to pay attention and listen”.
◾Did Obama really improve race relations?
◾Obama’s presidency: Grades A to F
The country’s first black president, now 55, was first elected in 2008 on a message of hope and change.
His successor, Donald Trump, has vowed to undo some of Mr Obama’s signature policies. He will be sworn into office on 20 January.
Striking an upbeat tone, Mr Obama said that the peaceful transfer of power between presidents was a “hallmark” of American democracy.
But, he outlined three threats to American democracy – economic inequality, racial divisions and the retreat of different segments of society into “bubbles”, where opinions are not based on “some common baseline of facts”.
‘Back to where it all started’
Returning to Chicago, where he first declared victory in 2008, Mr Obama delivered a positive message to Americans after a divisive election campaign which saw to Mr Trump defeat Democrat Hillary Clinton.
Mr Obama said that young Americans – including those who worked on his campaigns, and who believe “in a fair, just, inclusive America” – left him feeling “even more optimistic about this country than I was when we started”.
In choosing Chicago, Mr Obama had earlier said he wanted to return to “where it all started” for him and First Lady Michelle Obama, instead of delivering the speech from the White House.
The address was written with the idea of speaking to all Americans, including Trump supporters, officials said.Mr Obama’s trip to Chicago is his last as president, and his 445th journey aboard Air Force One.
He said it was in the city as a young man, “still trying to figure out who I was, still searching for purpose in my life”, that he “witnesses the power of faith and dignity of working people in the face of struggle and loss”.
More than 20,000 people had been expected to attend the farewell address at McCormick Place, the largest convention centre in North America and the venue for Mr Obama’s speech after he defeated Mitt Romney in the 2012 election.
The tickets were given out free, but were selling online for more than $1,000 (£820) each hours ahead of the speech.
First Lady Michelle Obama, Vice-President Joe Biden and his wife Jill Biden were all in attendance.
Presidential farewell addresses have long been an American political tradition.
Former Presidents George W Bush and Bill Clinton delivered theirs from the White House, while George Bush Snr gave his at the West Point military academy.
As he leaves the White House, President Obama is viewed favourably by 57% of Americans, according to an Associated Press-NORC Center for Public Affairs Research poll, a similar level to Bill Clinton when he left office.