Get breaking news alerts and special reports. The news and stories that matter, delivered weekday mornings.

President Obama strongly defended a globalized, interconnected world in his final speech at the United Nations on Tuesday, arguing that open markets, capitalism and democracy should remain the guiding forces of the international order.

Obama slammed what he described as “aggressive nationalism” and “crude populism” of populist leaders who are wary of internationalism growing in influence around the world. Obama did not directly mention the British vote to leave the European Union or the rise of GOP presidential nominee Donald Trump, but his speech was obviously aimed at pushing back against such developments, which he has strongly opposed.

"A nation ringed by walls would only imprison itself," Obama said.

Related: Obama to Highlight Foreign Policy Accomplishments at U.N.

Later in the speech, Obama noted, “the world is too small for us to simply build a wall.”

It was a speech that sought to highlight the significant progress over the course of Obama's presidency on such issues as climate change, economic security and advocating for democratic freedoms — as he seeks to cement his legacy.

“The integration of our global economy has made life better for billions of our women and children,” he said, adding “our international order has been so successful we take it as a given that great powers no longer fight wars.”

It was also a speech that underscored that, despite the progress, challenges remain as the world grapples with the rise of ISIS and eyes North Korea's nuclear ambitions.

Obama also specifically spoke out against what he called a “strong man” leadership model, arguing instead for nations with democratic governments and strong independent news institutions. He seemed to contrast with the leadership approaches of both Trump and Vladimir Putin.

“Those of use who believe in democracy, we need to speak out forcefully,” he said adding, “I believe in a liberal political order.”

The president acknowledged the growing gap between the rich and poor, particularly in the U.S. He argued policies such as expanding labor unions and increasing education would help address these disparities.

The Morning Rundown Get a head start on the morning's top stories. This site is protected by recaptcha

“The answer cannot be a simple rejection of global integration,” Obama said. “We have to make sure the benefits of such integration are broadly shared.”

Obama arrived in office in 2009 set on winding down the wars in Iraq and Afghanistan. But his speech illustrated how the world has changed in the last eight years.

While U.S. troops remain in both nations, the president seemed as worried about economics and culture as military issues.

“We are seeing the same forces of global integration that have made us interdependent also expose deep fault lines in the existing international order,” the president said.

President Obama arrives at the United Nations to address the General Assembly on Sept. 20. NBC News

But he argued, “we must reject any forms of fundamentalism or racism or a belief in ethnic superiority.”

Obama also used the speech to list what he views as his signature achievements on foreign policy: normalizing relations with Cuba, reaching a nuclear agreement with Iran, helping push Myanmar towards democracy, agreeing with nations around the world on goals to reduce emissions and fight climate change.

The president addressed some of the issues that are viewed as shortcomings of his foreign policy approach.

He argued diplomacy was the only way to end the civil war in Syria. He called for greater international cooperation to fight ISIS.

Obama recently pledged that the U.S. would accept 110,000 refugees, up from about 85,000 this year. The administration recently announced the U.S. had reached its goal of admitting 10,000 refugees from Syria this year.

Children play at the yard of an abandoned school used by volunteers for hosting families of refugees from Syria and Afghanistan in Athens on June 27, 2016. ARIS MESSINIS / AFP - Getty Images

The U.S. remains far behind the pace of nations like Germany in accepting refugees.

But in increasing the number of refugees now, the Obama administration is both trying to address a growing humanitarian crisis, particularly in Syria but also reject the anti-Muslim, anti-refugee rhetoric of Trump.

In his 2008 campaign, Obama promised to rebuild American relations with countries abroad who had opposed the Iraq War and felt the Bush administration too often acted internationally without consulting other nations. In a September 2009 address to the United Nations General Assembly, Obama promised a “a new era of engagement based on mutual interest and mutual respect.”

Related: Trump's and Obama's Views on Globalization Reflect Broader Gap

In 2008, the Pew Research Center asked people in 24 countries around the world if they had could count on President George W. Bush to do the right thing on foreign affairs issues. Majorities in only three of the 24 countries expressed confidence in Bush.

Last year, Pew asked a similar question. In 32 of the 40 countries Pew surveyed, a majority of the people had confidence in Obama’s global leadership.

But Obama’s 2009 speech also shows some goals he did not accomplish.

The president has not been able to convince Republicans in Congress to support the closing of the military prison at Guantanamo Bay or made much progress in achieving a permanent solution to the tensions between the Palestinians and the Israelis.

A Navy guard patrols Camp Delta's detainee recreation yard during the early morning at Guantanamo Bay naval base in a July 7, 2010 handout. President Barack Obama urged lawmakers on Tuesday to give his plan to close the U.S. military prison at Guantanamo Bay, Cuba, a "fair hearing" and said he did not want to pass the issue to his successor when he leaves the White House next year. R. Holzworth/US Army / Reuters

Even on issues like fighting climate change and reducing the nuclear weapons stockpiles around the world, Obama’s achievements have been mixed.

Obama successfully reached an agreement with Iran to reduce its nuclear program, but North Korea appears to have increased its nuclear capacity over the last 8 years.

Al Qaeda has been weakened, as Obama hoped for in 2009, but ISIS has emerged as a major threat to commit terrorist acts across the globe.

Obama in 2009 argued that “power is no longer a zero-sum game” and suggested the time was over for “alignments of nations rooted in the cleavages of a long-gone Cold War.” But Russian president Vladimir Putin appears to view international relations in this model Obama criticized and has taken actions in the Ukraine and Iran that the American president has opposed but could not prevent.