AL-ASAD AIRBASE, Iraq — In an unannounced trip to Iraq on Wednesday, President Donald Trump staunchly defended his decision to withdraw U.S. forces from neighboring Syria despite a drumbeat of criticism from military officials and allies who don’t think the job fighting Islamic State militants there is over.

Trump, making his first presidential visit to troops in a troubled region, said it’s because the U.S. military had all but eliminated IS-controlled territory in both Iraq and Syria that he decided to withdraw 2,000 forces from Syria. He said the decision to leave Syria showed America’s renewed stature on the world stage and his quest to put “America first.”

“We’re no longer the suckers, folks,” Trump told U.S. servicemen and women at al-Asad Airbase in western Iraq, about 100 miles west of Baghdad. “We’re respected again as a nation.”

The decision to pull U.S. forces from Syria, however, stunned national security advisers and U.S. allies and prompted the resignations of Defense Secretary Jim Mattis, who was not on the trip, and the U.S. envoy to the coalition fighting the Islamic extremist group. The militant group, also known as ISIS, has lost nearly all its territory in Iraq and Syria but is still seen as a threat.

Iraq declared IS defeated within its borders in December 2017, but Trump’s trip was shrouded in secrecy, which has been standard practice for presidents flying into conflict areas.

Air Force One, lights out and window shutters drawn, flew overnight from Washington, landing at an airbase west of Baghdad in darkness Wednesday evening. George W. Bush made four trips to Iraq as president and President Barack Obama made one.

During his three-plus hours on the ground, Trump did not meet with any Iraqi officials, but spoke on the phone with Iraqi Prime Minister Adel Abdul-Mahdi. He stopped at Ramstein Air Force Base in Germany on his way back, for a second unannounced visit to troops and military leaders.

Trump’s Iraq visit appeared to have inflamed sensitivities about the continued presence of U.S. forces in Iraq. The two major blocs in the Iraqi parliament both condemned the visit, likening it to a violation of Iraqi sovereignty.

The airbase where Trump spoke is about 155 miles from Hajin, a Syrian town near the Iraqi border where Kurdish fighters are still battling IS extremists. Trump has said IS militants have been eradicated, but the latest estimate is that IS still holds about 60 square miles of territory in that region of Syria, although fighters also fled the area and are in hiding in other pockets of the country.

Mattis was supposed to continue leading the Pentagon until late February but Trump moved up his exit and announced that Patrick Shanahan, deputy defense secretary, would take the job on Jan. 1 and he was in “no rush” to nominate a new defense chief.

“Everybody and his uncle wants that position,” Trump told reporters traveling with him in Iraq. “And also, by the way, everybody and her aunt, just so I won’t be criticized.”

Critics said the U.S. exit from Syria, the latest in Trump’s increasingly isolationist-style foreign policy, would provide an opening for IS to regroup, give Iran a green light to expand its influence in the region and leave U.S.-backed Kurdish forces vulnerable to attacks from Turkey.

“I made it clear from the beginning that our mission in Syria was to strip ISIS of its military strongholds,” said Trump, who wore an olive green bomber style jacket as he was welcomed by chants of “USA! USA!” and speakers blaring Lee Greenwood’s song, “God Bless the USA.”

“We’ll be watching ISIS very closely,” said Trump, who was joined by first lady Melania Trump, but no members of his Cabinet or lawmakers. “We’ll be watching them very, very closely, the remnants of ISIS”

Trump also said he had no plans to withdraw the 5,200 U.S. forces in Iraq. That’s down from about 170,000 in 2007 at the height of the surge of U.S. forces to combat sectarian violence unleashed by the U.S.-led invasion to topple dictator Saddam Hussein.

Trump spoke on the phone with the prime minister, but the White House said security concerns and the short notice of the trip prevented the president from meeting him face-to-face.

The prime minister’s office said “differences in points of view over the arrangements” prevented the two from meeting but they discussed security issues and Trump’s order to withdraw U.S. troops from Syria over the phone. Abdul-Mahdi’s office also did not say whether he had accepted an invitation to the White House. But Trump press secretary Sarah Huckabee Sanders told reporters on the flight back that the Iraqi leader had agreed to come.

Trump said that after U.S. troops in Syria return home, Iraq could still be used to stage attacks on IS militants.

“We can use this as a base if we wanted to do something in Syria,” he said. “If we see something happening with ISIS that we don’t like, we can hit them so fast and so hard” that they “really won’t know what the hell happened.”

Trump said it’s time to leave Syria because the U.S. should not be involved in nation-building, and that other wealthy nations should shoulder the cost of rebuilding Syria. He also said Turkish President Recep Tayyip Erdogan has agreed to battle “any remnants of ISIS” in Syria, which shares a border with Turkey.

“The nations of the regions must step up and take more responsibility for their future,” Trump said, promising a “strong deliberate and orderly withdrawal” of forces from Syria

Trump had faced criticism for not yet visiting U.S. troops stationed in harm’s way as he comes up on his two-year mark in office. He told The Associated Press in October that he “will do that at some point, but I don’t think it’s overly necessary.

Trump told reporters that he had planned to make the trip three or four weeks ago, but word of the trip started getting out and forced him to postpone it.

Iraqi leaders declared an end to combat operations against IS a year ago but the country’s political, military and economic situation remains uncertain. It continues to experience sporadic bombings, kidnappings and assassinations, which most people attribute to IS.

On Dec. 15, the U.S.-led coalition launched an airstrike in support of Iraqi troops who were chasing IS fighters toward a tunnel west of Mosul. The strike destroyed the tunnel entrance and killed four IS fighters, according to the U.S. military in Baghdad. The last U.S. service member to die in Iraq was in August, as the result of a helicopter crash in Sinjar.

Trump had planned to spend Christmas at his private club in Florida, but stayed behind in Washington due to the partial government shutdown.

Trump campaigned for office on a platform of ending U.S. involvement in foreign trouble spots, such as Syria, Afghanistan and Iraq. The Pentagon is also said to be developing plans to withdraw up to half of the 14,000 American troops still serving in Afghanistan.

Associated Press writers Deb Riechmann and Lolita C. Baldor in Washington and Philip Issa in Baghdad contributed to this report.