During his remarks, the Commander-in-Chief encouraged US service members to keep up the fight and vowed to continue the fight against ISIS from Iraq.
The president told reporters traveling with him that he wants to get US soldiers home from Syria and that Iraq can still be used as a base to stage attacks on Islamic State militants if needed, according to the Associated Press.
The visit followed the decision of the American leader to slash troop levels in Afghanistan and pull out entirely from Syria.
Trump said Deputy Defense Secretary Patrick Shanahan, whom he named on Sunday to replace Mattis in an acting capacity starting on January 1, "could be there for a long time".
Faced with growing criticism on his failure to build his anti-immigration wall on the border with Mexico, trump wants to score positive headlines and buy himself more time by delivering on his other key campaign promises, including returning troops back home.
"The United States can not continue to be the policeman of the world", he added, saying his his generals have had "enough time" to fight the war and that they have been told to leave Syria without any delays. "We've knocked them silly". "Two years ago, when I became President, they were a very dominant group". And others will do it to.
While there has been no full-scale violence in Iraq since ISIL suffered a series of defeats past year, United States troops train and advise Iraqi forces still waging a campaign against the group.
Trump told reporters traveling with him that if needed, the USA can attack IS "so fast and so hard" that they "won't know what the hell happened".
The policy changes, defended by Trump as an exit from wars where the United States no longer needs to be expending lives and money, have sparked alarm among U.S. allies.
Reuters reported last week that the Pentagon was considering using special operations teams to target Islamic State militants in Syria, based out of Iraq. Hey, I just got them a pay raise. We are in countries most people haven't even heard about.
"Trump sets new Christmas record: Finally makes first visit to combat troops", it reported, adding that "Trump's loyalty to his country has been called into question since the beginning of his presidency" because of allegations - still unfounded - of Russian Federation "collusion".