President Trump and first lady Melania Trump have made a surprise trip to Iraq to visit U.S. troops. The trip marked Mr. Trump's first visit to Iraq, as well as his first visit to a combat zone as commander-in-chief.

"@FLOTUS Melania and I were honored to visit our incredible troops at Al Asad Air Base in Iraq. GOD BLESS THE U.S.A.!," Mr. Trump wrote on Twitter Wednesday afternoon. He posted a short video clip that shows him greeting the troops, shaking hands and signing autographs.

.@FLOTUS Melania and I were honored to visit our incredible troops at Al Asad Air Base in Iraq. GOD BLESS THE U.S.A.! pic.twitter.com/rDlhITDvm1 — Donald J. Trump (@realDonaldTrump) December 26, 2018

The president and first lady met with service members at the Al Asad Airbase on the outskirts of Baghdad. They were on the ground in Iraq for about three and a half hours. Mr. Trump had been criticized for not visiting troops during the holidays — a long-held tradition for American presidents.

Get Breaking News Delivered to Your Inbox

"President Trump and the First Lady traveled to Iraq late on Christmas night to visit with our troops and Senior Military leadership to thank them for their service, their success, and their sacrifice and to wish them a Merry Christmas," White House Press Secretary Sarah Sanders wrote on Twitter.

President Donald Trump and first lady Melania Trump greet military personnel during an unannounced visit to Al Asad Air Base, Iraq, December 26, 2018. JONATHAN ERNST/REUTERS

After meeting with troops and military leaders, the president told reporters he chose Iraq because he has been talking about the country for "many years." More than 5,000 American troops are deployed in Iraq — the lowest number since a U.S.-led coalition invaded the Middle Eastern nation in 2003.

Mr. Trump also defended his decision to withdraw the approximately 2,000 U.S. troops fighting ISIS in Syria, which drew criticism from Democrats and many Republicans. He said generals asked him to postpone the move, but that he told them they've had "enough time."

The president said American forces had "knocked (ISIS) silly" and that Turkey's President Recep Tayyip Erdoğan had assured him the Turkish military would continue to fight the militants.

"The United States cannot continue to be the policeman of the world," Mr. Trump said.

Mr. Trump emphasized that other countries will need to invest more in their own protection. "We are no longer the suckers of the world," he said.

The unexpected trip to Iraq comes as the president faces several challenges at home. The government remains partially shut down as negotiations between the White House and lawmakers continue to be locked in an impasse over the president's unwavering $5 billion demand for border wall funds. And the stock market has slumped, fueling the president's ire at the chairman of the Federal Reserve.

President Donald Trump poses for a photo with military personnel during an unannounced visit to Al Asad Air Base, Iraq, December 26, 2018. Jonathan Ernst / REUTERS

Asked about the stalemate in talks to reopen the government, Mr. Trump said the shutdown will continue until lawmakers approve funding to construct a wall along the U.S.-Mexico border.

"We need a wall. We need safety for our country. Even from this standpoint. We have terrorists coming in through the southern border," he said.

Mr. added that he plans on "going to the wall" on the southern border before his State of the Union address early next year.

Last week, rifts with the president over foreign policy prompted Defense Secretary James Mattis to submit his resignation. On Sunday, the president ordered Mattis to leave his post by Jan. 1 and announced that deputy defense secretary Patrick Shanahan will take over as acting secretary.