President Donald Trump took a whirlwind, secret trip to Iraq this week — and things didn’t go quite as smoothly as planned.

In his first visit as president to a conflict zone, Trump stopped off in the country for three hours on Wednesday in order to meet some of the roughly 5,000 US troops stationed there, before continuing on to Germany.

His visit came amid much upheaval: About a week ago, Trump hastily declared that he had defeated ISIS, and that the US would pull its troops out of Syria. The abrupt move was reportedly resisted by Secretary of Defense James Mattis, who appealed to the president to reconsider and then resigned when his counsel fell on deaf ears. Brett McGurk, the US special envoy to the coalition to defeat ISIS, also submitted his resignation last week in protest. The president also decided to draw down the US troop presence in Afghanistan, according to officials.

It’s a longstanding tradition for presidents to conceal their trips to war zones for security reasons. But though White House press pool reporters were sworn to secrecy, bloggers and aviation enthusiasts drew attention to the mystery trip on Twitter and prompted speculation about the president’s whereabouts.

As Trump later tweeted, he spent his time in Iraq meeting with US troops at the Al Asad Air Base, shaking hands and signing MAGA hats. However, the president failed to meet with any Iraqi officials while in the country — despite the fact that the US invaded the country in 2003 and has had a continuous troop presence there ever since.

Though the trip had reportedly been planned for weeks, Iraqi Prime Minister Adil Abdul-Mahdi was invited to meet the president only two hours in advance, and was unable to make it to the event. The two leaders spoke over the phone instead, and the prime minister later said that the meeting was canceled because of a disagreement over how to conduct the session.

The president also reportedly exposed a covert Navy SEAL deployment. According to Newsweek, Trump posed with members of a special operations unit for photographs and then posted a video including this scene on Twitter without blurring out their faces or obscuring their identity — which violates accepted security protocol.

There’s also some question about whether troops, some of whom had Trump sign MAGA hats, violated a Department of Defense rule against active-duty personnel engaging in “partisan political activities.”

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. pic.twitter.com/s2hntnRwpw — Sarah Sanders (@PressSec) December 26, 2018

After Trump left the country, Iraqi politicians and lawmakers, who were angered and insulted by the US president’s swift and unannounced visit, demanded that US troops leave as well. (While the White House has plans to withdraw troops from Syria and from Afghanistan, there are no plans to do the same in Iraq.)

Sabah al-Saadi, the leader of Iraq’s Islah parliamentary bloc, requested an emergency parliament session “to discuss this blatant violation of Iraq’s sovereignty and to stop these aggressive actions by Trump who should know his limits: The U.S. occupation of Iraq is over,” Reuters reported.

Trump’s Iraq trip comes at a time of upheaval for the administration

The secret trip came amid a partial government shutdown and a chaotic time for the White House in terms of foreign policy. On December 19, the president said that the US would be withdrawing all of its roughly 2,000 troops from Syria, and that ISIS had been defeated there. (The next day, in a strange series of tweets, the president seemed to walk this last claim back somewhat.)

The Syria decision, in particular, shocked close US allies, politicians, and advisers, many of whom had advocated for a more sustained US military presence there to stabilize the country and ensure that ISIS forces didn’t return. Experts have also argued that leaving Syria as a battleground for Russia, Iran, Israel, and Turkey to fight out their regional tensions and proxy wars is a dangerous and short-sighted move.

None of this seemed to faze the president much, who posted a video on Thursday of himself and first lady Melania Trump smiling and shaking hands with troops at the Al Asad Air Base in Iraq, underscored with patriotic music.

And though he told reporters on Wednesday that he had no plans to pull troops out of Iraq, Trump did continue to emphasize his discomfort with the presence of US troops in foreign countries. “We are spread out all over the world. We are in countries most people haven’t even heard about. Frankly, it’s ridiculous,” the president said.