President Donald Trump made an unannounced visit to Iraq on Wednesday, leaving behind a partially shuttered U.S. government to greet American troops helping hold off extremists in a country where thousands of Americans died during the recent war.

It comes a week after Trump stunned his national security advisers by announcing that he would withdraw U.S. troops from neighboring Syria where they have been fighting Islamic State militants. Defense Secretary Jim Mattis abruptly resigned following the announcement, and Trump's decision rattled allies around the world, including in Iraq.

Trump's trip was shrouded in secrecy. Air Force One flew overnight from Washington, landing at an airbase west of Baghdad under the cover of darkness Wednesday evening. It is his first visit with troops stationed in a troubled region.

Fifteen years after the 2003 invasion, the U.S. still has more than 5,000 troops in Iraq supporting the government as it continues the fight against remaining pockets of resistance by the Islamic State group. IS has lost a significant amount of territory in Iraq and Syria but is still seen as a threat.

Trump, who speaks often about his support for the U.S. military, had faced criticism for not yet visiting U.S. troops stationed in harm's way as he comes up on his two-year mark in office. He told The Associated Press in an interview in October that he "will do that at some point, but I don't think it's overly necessary." He later began to signal that such a troop visit was in the offing.

Trump had planned to spend Christmas at his private club in Florida, but stayed behind in Washington due to the shutdown. It's unclear whether his trip to Iraq was added after it became apparent that the government would be shut down indefinitely due to a stalemate between Trump and congressional Democrats over the president's demand for a wall along the U.S.-Mexico border.

Adding to the tumult, the stock market has been experiencing heavy losses over concerns about a slowing global economy, Trump's trade war with China and the president's public slamming of the Federal Reserve and its chairman over interest rate hikes by the independent agency.

Trump's visit comes at a time when his Middle East policy is in flux. He went against the views of his top national security advisers in announcing the Syria withdrawal, a decision that risks creating a vacuum for extremists to thrive.

There are dire implications in particular for neighboring Iraq. The Iraqi government now has control of all the country's cities, towns and villages after fighting its last urban battles against IS in December 2017. But its political, military and economic situation remains uncertain, and the country continues to experience sporadic bombings, kidnappings and assassinations, which most people attribute to IS.

Iraqi Prime Minister Adel Abdul-Mahdi recently said Iraqi troops could deploy into Syria to protect Iraq from threats across its borders. Iraq keeps reinforcements along its frontier to guard against infiltration by IS militants, who hold a pocket of territory along the Euphrates River.

Trump campaigned for office on a platform of ending U.S. involvement in foreign trouble spots, such as Syria, Afghanistan and Iraq. The Syria decision will ultimately affect all of the approximately 2,000 troops deployed in the war-torn country. The Pentagon is also said to be developing plans to withdraw up to half of the 14,000 American troops still serving in Afghanistan.

During the presidential campaign, Trump blamed Democrat Hillary Clinton for the rise of IS, due to the withdrawal of U.S. troops from Iraq at the end of 2011 during her tenure as secretary of state.

President George W. Bush is the one who set the 2011 withdrawal date as part of an agreement with the Iraqi government to gradually shrink the U.S. footprint and slowly hand off security responsibilities to the government and Iraqi security forces.

His successor, President Barack Obama, wanted to leave a residual force in Iraq to help the government manage ongoing security challenges. But he ultimately went ahead with the scheduled pullout in 2011 after Iraqi's political leaders rejected terms the U.S. sought for legal protections for the U.S. troops that would have remained.

Two of Trump's recent predecessors visited Iraq early in their terms.

Bush visited Iraq in November 2003, about eight months after that conflict began. Due to security concerns, Bush waited until 2006 to make his first visit to Afghanistan.

Obama visited Iraq in April 2009, the first year of his eight years in office, as part of an overseas tour. He visited Afghanistan in 2010.

Vice President Mike Pence visited Afghanistan in December 2017, not long after Trump outlined a strategy to break the stalemate in America's longest war. Pence met with Afghan leaders and visited with U.S. troops stationed in the country. Trump has not visited Afghanistan.

__

Associated Press writer Philip Issa contributed to this report.

___

Follow Darlene Superville on Twitter: http://www.twitter.com/dsupervilleap