President Obama told Peruvians Sunday night that America has often "fallen short of our ideals" of democracy, rule of law, a free press, an independent judiciary, free markets, and a social welfare system to help the disadvantaged.

Here's a transcript:

In terms of reflecting on the United States presidency as I have been traveling, I think the main reflection I have and the main advice that I give to the incoming president is, the United States really is an indispensable nation in our world order.

I say that as somebody who has gone out of his way to express respect for every country and its people and to consistently acknowledge that many of the challenges we face are not challenges that America can solve on our own. But what I also know that the basic framework of the world order coming out of World War II and then on through the end of the Cold War, was shaped by a set of ideals and principles that have worked for the vast majority of people not just in America but around the world.

The notion of democracy. And rule of law. And a free press. And independent judiciary. And open markets. And a social welfare state to moderate some of the sharp edges of capitalism. And, you know, lifting up issues of human rights and investing in public health and development not just in our own borders but elsewhere in the world. And working with multilateral institutions, like the United Nations, making sure we're upholding international norms and rules.

That's what has made the modern world. And there have been times when we have not observed some of the norms as well as we should and have been accused of hypocrisy here in Latin America. There have been times when countries have felt disrespected and on occasion have had cause for that. And there were teams when we haven't observed the values in our own country and have fallen short of our ideals, but that basic structure is the reason why the world is much wealthier, much more secure, and yes, less violent, healthier, and better educated, more tolerant than 50 years ago. That requires constant work. It doesn't just happen on its own."

This is not the first time the president has criticized his own country while traveling abroad. On Saturday he accused America of sexist banking rules, claiming women were required to have men co-sign loan applications up until 1996.

Earlier:

September 9, 2016: 18 Times Obama Trashed America in Asia

March 25, 2016: 15 Times Obama Talked Down America in Cuba and Argentina