President Barack Obama has called on Americans to defend their democracy in his farewell speech in Chicago.