He says that's a job that should be shouldered by other rich nations.
"I made it clear from the beginning that our mission in Syria was to strip ISIS of its military strongholds", Trump told troop Al Asad Air Base. west of Baghdad.
One of those critics was Mattis, who said in a candid resignation letter last week that his views did not align with the president's, particularly in regard to the treatment of USA allies.
US President Donald Trump takes a photo as he greets members of the US military.
They and other officials warned Trump that leaving the region now would allow for ISIS, or another terror group, to regain a foothold.
President Trump, accompanied by National Security Adviser John Bolton, third from left, first lady Melania Trump, fourth from right, US Ambassador to Iraq Doug Silliman, third from right, and senior military leadership, spoke to members of the media at Al Asad Air Base.
He left Washington amid huge turmoil in the U.S.
He did call troops stationed around the world, but made no personal visits, the network news said.
More than 5,000 American troops are deployed in Iraq - the lowest number since a US -led coalition invaded the Middle Eastern country in 2003. The trip also comes after Trump announced that he was pulling USA forces out of neighboring Syria.
The Latest: Trump defends withdrawal of troops from Syria
Trump follows a long tradition of presidents visiting troops overseas. Pentagon officials at the time refused to discuss specifics, including the timeline, citing operational security for the roughly 2,000 USA troops in Syria.
Mr Trump said the U.S. had no plans to pull out of Iraq, Reuters reports.
Trump has also faced negative headlines for wanting to pull troops from Afghanistan where they have been since 2001.
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". "We've knocked them silly".
"I think a lot of people are going to come around to my way of thinking. You've had enough time", he said he had told his generals.
Although the visit took place in considerable secrecy, speculation had been mounting that Trump might make such a trip.
President Donald Trump, who is visiting Iraq, says he has "no plans at all" to remove USA troops from the country.
On his way home from Iraq, he will also stop to visit troops at Ramstein Air Base in Germany.
Inside Katrina Kaif's Christmas Bash With Salman Khan And Shah Rukh Khan
Shah Rukh, in his movie Zero , made a comeback after the gap of nearly one and a half year. It is Shah Rukh Khan's first movie since Jab Harry Met Sejal bombed past year .
Third Canadian detained in China, Canadian media says, citing ministry
The official said Canadian authorities were aware of the detention but gave no details. In this case, official and quasi-official Chinese sources have been clear.
Don't Return Asylum Seekers to Mexico
In response, Mexico's foreign ministry underscored that it still has the right to admit or reject the entry of foreigners into its territory.