President Donald Trump used a lightning visit to Iraq -- his first with US troops in a conflict zone since being elected -- to defend withdrawal from Syria and to declare an end to America's role as the global "policeman."

Trump landed at 7:16 pm local time at Al-Asad Air Base in western Iraq, accompanied by his wife Melania, following what he described as a stressful, secrecy shrouded flight on a "pitch black" Air Force One.

The president spoke to a group of about 100 mostly special forces personnel and separately with military leaders before leaving a few hours later, an AFP correspondent said. A planned meeting with Iraqi Prime Minister Adel Abdel Mahdi was scrapped and replaced by a phone call, the premier's office said.

White House video showed a smiling Trump shaking hands with camouflage-clad personnel, signing autographs and posing for photos.

Morale boosting presidential visits to US troops in war zones have been a longstanding tradition in the years following the September 11, 2001 terrorist attacks.

Trump has taken considerable criticism for declining to visit in the first two years of his presidency. But speculation had been mounting that he would finally make the gesture following his controversial decision to slash troop levels in Afghanistan and withdraw entirely from Syria.

At the Iraqi military base, Trump sought to defend his "America first" policy of pulling back from multinational alliances, including what to many Americans seem like the endless wars of the Middle East.

"It's not fair when the burden is all on us," he said. "We don't want to be taken advantage of any more by countries that use us and use our incredible military to protect them. They don't pay for it and they're going to have to."

"We are spread out all over the world. We are in countries most people haven't even heard about. Frankly, it's ridiculous," he added.

Trump told reporters he had overruled generals asking to extend the Syria deployment, where about 2,000 US forces, joined by other foreign troops, assist local fighters battling the Islamic State jihadist group.

"You can't have any more time. You've had enough time," he said he told the top brass.

Time to withdraw troops?

The drawdowns -- and the abrupt way that they were announced -- helped lead to the resignation of Trump's defense secretary, Jim Mattis, who has been one of the administration's key heavyweights.

In his unusually forcefully worded resignation letter, Mattis appeared to chide Trump when he stressed his own "strongly held" views on "treating allies with respect and also being clear-eyed about both malign actors and strategic competitors."

Trump has also taken flak from France and other foreign partners and senior figures in his own Republican party.

However, the president has made disentangling America from its wars a priority since his 2016 election and he said in Iraq that the US would no longer be treated as "suckers," CNN reported.

The Islamic State group, which once controlled swaths of territory in Iraq and Syria, has been driven mostly into hiding.

On Wednesday, Trump said "we've knocked them out," although he appeared to hedge his bets -- following widespread criticism that his victory declaration is premature -- when he added that Iraq might be used as a future base for operations in Syria, CNN reported.

In Afghanistan, Trump wants to withdraw about half of the 14,000 soldiers locked in a war against Taliban guerrillas that has long resembled a stalemate.

The Iraq trip will also go some way to ending criticism over Trump's failure to meet soldiers on the ground, even as he repeatedly touts his support for the military in campaign rallies.

And it provides some distraction from a rising tide of domestic political problems, including the government shutdown caused by Trump's row with Congress over funding for a US-Mexico border wall. Pressure is also mounting from a series of criminal probes into Trump's finances and links to Russia.

According to Trump, the flight into Iraq was unlike anything he'd previously experienced.

"If you would have seen what we had to go through in the darkened plane with all window closed with no light anywhere -- pitch black," he said.

"I've been on many airplanes. All types and shapes and sizes."

"So did I have a concern? Yes I had a concern."