U.S. President Donald Trump overrode his top national security aides, blindsided U.S. ground commanders, and stunned lawmakers and allies with his order for U.S. troops to leave Syria, a decision that upends American policy in the Middle East.

The result, said current and former officials and people briefed on the decision, will empower Russia and Iran and leave unfinished the goal of erasing the risk that Islamic State, or ISIS, which has lost all but a sliver territory, could rebuild.

Trump was moving toward his dramatic decision in recent weeks even as top aides tried to talk him out of it, determined to fulfill a campaign promise of limiting U.S. involvement militarily abroad, two senior officials said.

>> U.S. withdrawal from Syria shows Washington is an ally, but only to a point | Analysis ■ Despite the blow to its national security, Israel will bow to Trump’s Syria withdrawal | Analysis

The move, which carries echoes of Trump’s repudiation of the Iran nuclear deal and the Paris climate change accord, is in keeping with his America First philosophy and the pledge he made to end U.S. military involvement.

A former senior Trump administration official said the president’s decision basically was made two years ago, and that Trump finally stared down what he considered unpersuasive advice to stay in.

“The president won. His inclination was always not to be there,” said the former official who is close to the White House, saying a variety of senior advisers had all argued against pulling out.

In meetings with top advisers, Trump would ask: “What are we doing there? I know we’re there to fight ISIS, but we did it. Now what?” said the former official.

Trump understood, but rejected, arguments by senior advisers that U.S. troops were not on the front lines, numbered only 2,000 and markedly strengthened anti-Islamic State local forces, saying he wanted to get out once Raqqa and other ISIS strongholds fell.

Qualms in the Pentagon

A U.S. defense official said Trump’s decision was widely seen in the Pentagon as benefiting Russia as well as Iran, both of which have used their support for the Syrian government to bolster their regional influence. Iran also has improved its ability to ship arms to Lebanese Hezbollah for use against Israel.

Asked who gained from the withdrawal, the defense official, who spoke on condition of anonymity, replied: “Geopolitically Russia, regionally Iran.”

Another U.S. defense official, also speaking on condition of anonymity, said U.S military commanders had expressed concerns with the administration about what a rapid withdrawal would mean for U.S.-backed local forces fighting Islamic State.

The official said the plan to withdraw had caught the commanders by surprise.

Trump “destroyed ISIS safe haven in Syria & will lose the peace by withdrawing,” tweeted retired Army Vice Chief of Staff Jack Keane, who has been seen as a possible successor to Defense Secretary Jim Mattis. “ISIS will re-emerge, Iran a greater threat, will own all of Syria, Israel more in danger.”

Like other experts, Keane, who is also a Fox News analyst, said that by pulling out, Trump will surrender Washington’s ability to play a major role in framing a settlement of the Syrian civil war.

Charles Lister, an expert with the Middle East Institute thinktank, agreed. “It completely takes apart America’s broader strategy in Syria,” he said, “but perhaps more importantly, the centerpiece of the Trump administration policy, which is containing Iran.

“Syria is the jewel in the crown of Iran’s regional strategy,” he said.

The Trump administration dismissed that argument.

“These troops that we had in Syria were never there to counter Iran. They were always there to destroy the territorial caliphate of ISIS,” said a senior administration official. “And so I think the president was perfectly justified when he judged that mission was at an end.”

Frustration among Republicans, allies

Lawmakers from both parties complained that they were not briefed in advance of the decision. Republican Senator Jeff Flake, a member of the Senate Foreign Relations Committee, told Reuters that GOP senators expressed their frustration “in spades” during a lunch with Vice President Mike Pence.

French officials, speaking on condition of anonymity, said they were scrambling to find out exactly what the announcement meant and how it will affect their participation in U.S.-led coalition operations against Islamic State.

“If this turns out to be as bad as it sounds, then it’s a serious problem for us and the British because operationally the coalition doesn’t work without the U.S.,” said one French diplomat.

Syria’s civil war, which began in 2011, has killed hundreds of thousands of people, displaced around half the country’s pre-war 22 million population and defied all efforts at diplomatic resolution.

The pull-out may be an especially bitter pill for Jim Jeffrey, the U.S. special representative for Syria, who was the U.S. ambassador in Baghdad when former President Barack Obama decided to withdraw U.S. forces, undercutting his leverage.

As recently as in September, Jeffrey told reporters, “We are not in a hurry to pull out.”