UNITED NATIONS — President Barack Obama, in his eighth and last address to the UN General Assembly as the leader of the United States, at once defended his foreign policy of multilateral engagement and took a swipe at the Republican presidential nominee who is trying to replace him.

“The world is too small for us to simply build a wall and prevent it from affecting our own societies,” said Obama, the third speaker in a list of nearly 200 as each member and observer nation of the United Nations delivers remarks over the next several days.

The speech Tuesday morning was the second time that Obama has used the podium at the General Debate to attack Donald Trump’s stated desire to erect a wall along the United States’ border with Mexico.

Last year, Obama spoke more directly of “the building of walls to keep out immigrants.”

The metaphor also formed the spine of this year’s address, which forecast Obama’s intention to urge nations to show compassion to people seeking shelter in nations other than their own as migrants, refugees and those appealing for political asylum — a major theme of the General Assembly, which began with a summit on the issue.

Obama also presided over a summit Tuesday that aims to hike financing of global humanitarian appeals for refugees; increase ways in which refugees can be resettled; and place more refugees in school. All of those goals are more specific than the general ones pledged to on Monday by the UN’s member states, which adopted the New York Declaration on Refugees and Migrants.

advertisement | advertise on newsday

It was an address that called for more multilateral engagement and action by consensus while dismissing unilateral action as divisive and a relic of previous eras when nations were less in sync and the world was arguably more dangerous because of it.

“I believe that at this moment we all face a choice,” the president said during his 50-minute speech. “We can choose to press forward with a better model of cooperation and integration, or we can retreat into a world sharply divided and ultimately in conflict along age-old lines of nation and tribe and race and religion. I want to suggest to you today that we must go forward and not back.”

United Nations Secretary-General Ban Ki-moon holds up a smartphone as he addresses the 71st session of United Nations General Assembly at the UN headquarters in Manhattan on Sept. 20, 2016. Photo Credit: AFP/Getty Images / Jewel Samad

Obama defended his style, citing the recent nuclear deal with Iran, designed to curb that country’s nuclear ambitions and harness nuclear power solely for peaceful purposes, as an example of appropriate engagement. The deal has been received well by some analysts and sharply criticized by others as porous, allowing Iran too much leeway to still produce a nuclear weapon while benefiting financially from the deal because it lifted sanctions.

He praised the Paris Agreement on Climate Change — designed to curb emissions and slow environmental degradation — as the right thing to do and another example of cooperation for the good of the world. Two dozen more nations must ratify the document for it to go into effect.

As for the attempt to cooperate on how to resolve Syria’s civil war, Obama acknowledged that is unresolved and he defended the military actions the United States has taken in the theater.

“There is a military component to that,” he said, calling the Islamic State terrorist group attacking the Syrian government’s forces a “mindless, medieval menace” worthy of destruction though the group seeks the overthrow of Syrian President Bashar Assad, as Obama does.

Obama conceded that “in a place like Syria, where there’s no ultimate military victory to be won, we’re going to have to pursue the hard work of diplomacy that aims to stop the violence, and deliver aid to those in need, and support those who pursue a political settlement and can see those who are not like themselves as worthy of dignity and respect.”

United Nations Secretary-General Ban Ki-moon holds up a smartphone as he addresses the 71st session of United Nations General Assembly at the UN headquarters in Manhattan on Sept. 20, 2016. Photo Credit: AFP/Getty Images / Jewel Samad

Those words in support of military action were somewhat at odds with the unusually forceful speech delivered earlier Tuesday by UN Secretary-General Ban Ki-moon, who chided nations for a kind of doublespeak, fueling the conflict by either directly or indirectly providing support to combatants while expressing a desire for peace.

advertisement | advertise on newsday

“Powerful patrons that keep feeding the war machine also have blood on their hands,” said Ban, in his last address to the General Assembly as secretary-general. “Present in this hall today are representatives of governments that have ignored, facilitated, funded, participated in or even planned and carried out atrocities inflicted by all sides of the Syria conflict against Syrian civilians.”

Obama sought to conclude his speech on a hopeful note, drawing healthy applause at the close.

“This is what I believe: that all of us can be co-workers with God,” he said. “And our leadership, and our governments, and this United Nations should reflect this irreducible truth.”