Get breaking news alerts and special reports. The news and stories that matter, delivered weekday mornings.

LONDON — President Donald Trump has repeatedly railed against America’s “endless wars” in the Middle East and told voters he will bring U.S. troops home.

But in Thursday’s killing of Qassem Soleimani, the high-profile commander of Iran’s secretive Quds Force, which followed the posting of hundreds of American troops to the region earlier this week, the United States runs the risk of embroiling itself in another conflict.

The airstrike that killed Soleimani, a commander of Iran's military forces in Iraq, Syria, Lebanon and elsewhere throughout the Middle East, has already heightened tensions between the U.S and Iran.

"This strike was aimed at deterring future Iranian attack plans," the Department of Defense said in a statement.

But Iran’s Supreme Leader Ayatollah Ali Khamenei warned Friday that “a severe revenge awaits those who have tainted their filthy hands with his [Soleimani’s] blood.”

For long-term Iran-watchers, the ramifications of this are stark. Brett McGurk, the former U.S. special envoy for the coalition to defeat the Islamic State militant group, told NBC News’ Rachel Maddow on Thursday that the U.S. should "presume that we are in a state of war with Iran."

"We've been trying now for two administrations to try to re-prioritize out of the Middle East because it's been such a resource black, dark hole for us," he said. "It turns out now two administrations were sucked back in. I think it would be very difficult now to really significantly move forces and resources out."

Soleimani’s death comes after supporters of an Iranian-backed militia, Kataeb Hezbollah, stormed the compound of the American Embassy in Baghdad on Tuesday. The rioters were incensed by deadly U.S. airstrikes Sunday that hit weapons depots in Iraq and Syria that the U.S. said were linked to the Kataeb Hezbollah militia group. At least 25 fighters were killed.

The U.S. blames the militia for attacks in recent months on the bases of the U.S.-led coalition that is fighting ISIS, including the death of a U.S. contractor a week ago.

The Pentagon said Thursday that Soleimani had “approved” the attacks on the U.S. Embassy and had been actively developing plans to attack U.S. diplomats and service members in Iraq and elsewhere throughout the region.

Qassem Soleimani, commander of the Quds Force, in Tehran. AFP - Getty Images file

Let our news meet your inbox. The news and stories that matters, delivered weekday mornings. This site is protected by recaptcha

Norman Roule, a 34-year CIA veteran who oversaw national intelligence policy on Iran before he retired in 2017, said he believed it was “highly likely the U.S. would not have undertaken this action unless it believed doing so would have prevented the loss of American lives.”

This week’s escalation serves as further evidence that the aim of drawing down troops from the greater Middle East is a complex and fraught process and that to revise long-standing foreign policy positions is no simple task.

In October, the Trump administration ordered the withdrawal of some 1,000 troops from Syria, amounting to most of the U.S. military presence in the country. But as the troops left northern Syria, new soldiers were heading in to secure an expanse of oil fields in the country’s east.

For months, U.S. negotiators and the Taliban have been attempting to hammer out a deal that would see U.S. troops withdraw from Afghan soil, with no agreement thus far.

And an additional 14,000 U.S. troops have been deployed to the Gulf region since May in response to concerns over Iranian aggression. The U.S. blames Iran for attacks on oil tankers in the Persian Gulf last year and an attack on key oil sites in Saudi Arabia in September.

There have been other tense moments between the U.S. and Iran. In April, the Trump administration announced it was designating Iran’s Revolutionary Guard a foreign terrorist organization.

In June, Iran shot down a U.S. surveillance drone that the Revolutionary Guard said had entered Iranian airspace. U.S. Central Command said the aircraft was in international airspace.

But so far, both countries have edged away from the brink of an all-out conflict.

Middle East analysts told NBC News earlier Thursday, ahead of the news of Soleimani’s death, that the Trump administration risked embroiling the U.S. in a conflict with Iran if it did not swiftly engage with Tehran.

“Without a meaningful backchannel and engagement, it’s very hard not to see a slide into conflict or that Iran might provoke conflict,” Sanam Vakil, a senior research fellow at the London think tank Chatham House, said.

Clément Therme, a research fellow at Sciences Po, a political science institute in Paris, described Trump’s withdrawal from the 2015 Iranian nuclear pact as a “self-fulfilling prophecy” that has further destabilized the region.

“The Iran deal was also designed to de-escalate tensions with Iran in the region, it was not only a nuclear deal,” Therme said. “If he wants to avoid this ‘endless war’ that is his official priority because he is campaigning now, he will have to engage Iran secretly via Oman.”

Trump withdrew the United States from the nuclear agreement between Iran and world powers in 2018 and has imposed a wave of economic sanctions on the country's oil industry, as well as banking and other key sectors. The 2015 nuclear deal eased U.S. and United Nations sanctions on Iran in return for limits on Tehran's nuclear program.

Economic sanctions against Tehran were increasing the risk of conflict, Therme added, because “Iran considers that if it cannot export oil, then it has destabilized the region even more.”

Vakil said she understood Trump’s approach to the Middle East to be about moving away from the blank check of security guarantees for American partners to one that is more transactional and benefits the American interest.

Vakil said Trump had not yet succeeded in forcing partners and allies to share the burden of regional policy partly due to the controversial nature of his presidency.

For the U.S. to leave the region, Washington would have to help manage the resolution of the multiple interconnected regional conflicts and facilitate a “new security architecture” for the Middle East — such as the African Union or the Association of Southeast Asian Nations — so it could manage its own internal challenges without looking to an outside power, she said.

For now, Vakil concluded,“it’s very hard to see a fluid and successful exit for the United States in any meaningful way.”