(CNN) Donald Trump hasn't pulled his troops out of Iraq, despite his pledge to end America's grinding wars. It turns out he may not have to. The US is facing the possibility of being kicked out, and that would be a big win for Iran.

Officials in Iraq's parliament, where powerful blocs have unbreakable ties to Tehran, started a process to end the presence of foreign troops in the country, in a clear riposte to the US after it killed top Iranian commander Qasem Soleimani in a drone strike in Baghdad two weeks ago.

In the wake of the strike, joint US-Iraqi operations against ISIS were put on hold, and Iraq's caretaker prime minister said a US troop withdrawal was the only way to "protect all those on Iraqi soil," though this week he said that decision would be up to the next government.

But a US withdrawal could bring even more trouble, experts say. ISIS continues its attacks in the country, and without US and other foreign troops, the group would have more room to resurge. At the same time, Iran will be able to expand its already far-reaching powers in Baghdad.

Tehran and Washington have competed for influence in Iraq since the US 2003 invasion, and in that battle, Iran is already winning. Its consistent and coherent strategy, which the US lacks, has allowed Tehran to gradually weave itself into the fabric of everyday life in Iraq.

It has capitalized on years of war and occupation to form militia groups that have become official factions of the Iraqi military, while economically, it provides an enormous amount of exports that Iraqis have come to rely on. It has made surrogates out of senior Iraqi government officials and members of parliament.

Because of those links, the Iraqi parliament's decision to side with Iran after the attack on Soleimani is not surprising. The strike appears to have backfired, to the benefit of Iran's long-term goal: getting the US out of the region.

"Iran is the most influential state in Iraq now," said Fawaz Gerges, a professor of international relations at the London School of Economics and Political Science. "That power is only going to grow if the US leaves."

Qasem Soleimani was the commander of the Revolutionary Guard's Quds Force. He was killed in a US drone strike on January 3.

He said that the most important challenge for Iraq now was not ISIS, but rebuilding a working nation -- fighting corruption, changing the sectarian-based government to one based on citizenship and professionalizing the army, for example. Iran isn't interested in those goals, Gerges said, and a US withdrawal would embolden it further its reach across the Middle East.

"If the US leaves, people across the region will think that despite his flowery rhetorical devices, Trump does not really have a strategy for the Middle East and at the end of the day will fold and go home," Gerges said.

Being forced out would be a humiliating end to the US' long mission in Iraq, which has sucked up hundreds of billions of US taxpayers' money and left thousands of US soldiers dead.

US Secretary of State Mike Pompeo has denied the US will leave , but pointed to a possible reduction of numbers. Gerges sees that proposal as a face-saving exercise for the US that could allow the American troops to stay in small numbers for the fight against ISIS but essentially begin the process of withdrawal.

How Iran got a hold on Iraq

Much of Iran's power in Iraq comes through militia groups that have roots in the 1980s Iraq-Iran war. Recruiting fighters from Iraq wasn't that difficult. Iraq was a Shia-majority nation led for more than two decades by brutal dictator Saddam Hussein, born a Sunni.

Iran, which has long pitched itself as the world's leader of Shia Muslims, took in Shia prisoners of war and refugees, and turned them into soldiers who would go back to Iraq to act in Tehran's interests, according to the Center for Strategic and International Studies. Some became part of what is now known as the Badr Organization, the report said, both a militia group and an anti-US political party in Iraq today.

"Because of the institutional organizational capacity of those paramilitary groups, when Saddam fell and the repression that contained them ended, they flourished. They had the capacity to expand and to operate more overtly," said Jack Watling, a specialist in land warfare at the London-based Royal United Services Institute.

The fight against ISIS provided another recruitment opportunity for Iran, particular after the terrorist group took Mosul and the Iraqi military collapsed. It was at this time the Popular Mobilization Units (PMUs), a coalition of mostly Shia militias, formed and became a powerful force in the country, in the absence of a real army. They have since been officially folded into Iraq's military.

According to Watling, there are now around 113,000 salaried personnel in the powerful Tehran-backed Iraqi militia group. Of those, some 60,000 are actively deployable as fighters, and of those, 36,000 are directed by Iran.

In the 2018 Iraqi elections, the political wing of the PMUs, Fatah, won the second-highest number of seats in parliament, giving another powerful voice to Iranian interests in the Iraqi government.

Economically, Iran has ensured Iraq is dependent on it for energy, seeking loopholes and waivers from the US to get around sanctions and sell energy to its neighbor. Iraq is also Iran's second most important destination for its exports, after China, according to the Observatory of Economic Complexity, so Tehran wants to ensure its market across the border is well secured.

Iraqi protesters chant during a demonstration against state corruption, failing public services and unemployment in Baghdad on October 2, 2019.

Trump sends mixed messages

As Iran made steady headway in the Iraqi government and military, the US' objective in Iraq has changed so many times that it's become muddy and unfocused. Iraqi officials are growing weary of the changes that have come with each new US president, and the mixed signals being sent by the Trump administration.

Pompeo is struggling to send the message that the US is in Iraq to fight ISIS, while strikes on Iranians there and comments from Trump indicate otherwise.

Last year, Trump admitted in an interview with CBS News that he wanted to keep a base in Iraq "because I want to be looking a little bit at Iran because Iran is a real problem." The comment provoked Tehran, and sowed confusion in Iraq.

Watling said the US appears to have shifted its interests in Iraq from countering ISIS to countering Iran.

"If the US said our objective is a strong and stable Iraq, then in many ways their best course of action would be to collaborate closely with the Iranians. But it's not. Their wish to counter the Iranian government in many ways overrides their wish to support the Iraqi state. There are contradictions in US policy in the region," he said.

Watling questioned what Trump's "maximum pressure" campaign against Iran was aiming to achieve. Iran's long-term strategy in Iraq, on the other hand, is paying off.

"We have seen a broadly unified attempt to ensure that Iran underwrites and limits Baghdad's military capability and that they retain Iraq as a market for their exports and as an economic partner," he said.

Winning hearts and minds

Despite achieving the regime change the US was looking for, with the capture and execution of Saddam, the US left Iraq in 2011 with an unsteady government in place. It had no choice but to send troops back to put out fires with the spread of ISIS. Iran also took part in the fight against ISIS, but it continued with its drive to boost influence in Iraq.

But Iran is failing in one key area. It hasn't really won the hearts of the people.

Anti-government protesters galvanized by deep economic grievances that have accumulated over many years have found themselves facing off with Iranian-backed forces.

Demonstrators were rallying against endemic corruption and cronyism, which they blame on "confessionalism," a system of government introduced by the US that divides power based on sectarian affiliation. While Iran didn't create that status quo, it has had a stake in maintaining it

In video footage of some of the demonstrations, protesters can be heard yelling chants against both Iran and the US. Young Iraqis in particular don't want either the US or Iran in their country, said Joost Hitermann, who leads the International Crisis Group's Middle East and North Africa program.

"Iraqis want to get rid of both. Some might like one more than they other, and they don't want just one of the two alone there, to dominate their country," Hitermann said.

"Shia Iraqis may be loosely aligned with Iran, but they don't subscribe to the Iranian Ayatollah Ali Khamenei. The Iranian way is not all what Shia Iraqis want."