Iranian President Hassan Rouhani is welcomed by Iraqi Prime Minister Adil Abdulmehdi (R) at Iraqi Prime Ministry Palace in Baghdad, Iraq on March 11, 2019. Iranian Presidency - Handout | Anadolu Agency | Getty Images

Iranian president Hassan Rouhani has returned from his first-ever trip to Iraq with a raft of agreements for expanded trade, cross-border infrastructure, and pledges of greater cooperation with Baghdad. Leaders of both countries embraced strengthening ties — something Washington has been watching closely. Iran is upping its game in Iraq as U.S. influence recedes, deepening ties with its war-weary neighbor and betting on bilateral economic activity to help offset tough sanctions imposed by the Trump administration. Iraq is "another channel for Iran to bypass America's unjust sanctions ... this trip will provide opportunities for Iran's economy," a senior Iranian official on the trip was quoted as telling Reuters last week. The Trump administration reinstated sanctions on Iran last year for what it deemed "destabilizing and malign activities around the world," and the country's economy has since been in a tailspin. With a massive shared border and religious and cultural ties — and the major role of Iranian-backed paramilitaries in Iraq's defeat of the Islamic State — the Islamic Republic's influence in Iraq is entrenched. Rouhani and Iraqi Prime Minister Adel Abdul-Mahdi signed memorandums of understanding across sectors including trade, oil, health, mining, visa-free travel, and perhaps most significantly a railway that would connect Iraq's southern oil-rich city of Basra to Iran's border.

The Trump administration is grappling with the extent and limit of U.S. sanctions and power to counter Iran in a country like Iraq with such deep social, economic and cultural ties to Iran. Senior U.S. congressional adviser

U.S. officials see Iran's growing inroads into Iraq, and they don't like it. "Iran's actions are aimed at subverting Iraqi sovereignty and making Iraq dependent on Iran," a senior State Department official told CNBC on Monday. He echoed Secretary of State Mike Pompeo's recent charge that Tehran wanted to turn Iraq into a "vassal state." In turn, Rouhani has seized on the opportunity to scold the U.S., telling Iranian media last week that his country's ties with Iraq "cannot be compared to Iraq's relations with an occupying country like America, which is hated in the region." Iraqi President Barham Salih praised Iran's leadership, saying, "Iraq is lucky to be a neighbor with Iran," and describing good relations with Iran as "a fundamental interest for Iraq." Baghdad has sought to balance its ties with the U.S., Iran and the Gulf Arab states to avoid being a victim of the rivals' turf wars.

While sanctions have hit hard at key parts of Iran's economy, many Iranian companies doing business in Iraq don't need U.S. banks or resources to be successful, one senior U.S. congressional adviser told CNBC, speaking anonymously due to the sensitivity of the topic. "The Trump administration is grappling with the extent and limit of U.S. sanctions and power to counter Iran in a country like Iraq with such deep social, economic and cultural ties to Iran," the adviser said.

Iraq: Iran's gateway to the Mediterranean

"All the agreements enable an increased Iranian physical presence on Iraqi soil," Jessica Leyland, a Middle East analyst at risk consultancy firm AKE International, told CNBC. "There are two sides to this: the genuine need and desire for areas of cooperation on both side versus Iran's ability to use Iraq to connect its sphere of influences." The planned railway between the two countries is the most obvious example of this, Leyland said. "The train line will firstly extend to Basra, this will give Iran influence in Iraq's strategic port of Umm Qasr and expand influence in the neck of the Gulf. It is likely that it will in the near future extend through Iraq to Syria, a stated intention of Iran's, which will then give Iran access to the Mediterranean." The business promises made between the two countries show how much has changed since the brutal Iran-Iraq war of the 1980s, which killed more than a million people. Ever since the U.S. invasion toppled Saddam Hussein in 2003, Iran has sought to deepen its influence in Iraq and take advantage of its links to the country's now-ruling Shia majority.

Harming Iraqi interests?

Iran-Iraq trade currently stands at an estimated $12 billion annually and both governments have pledged to expand this to $20 billion. Iran is Iraq's third-biggest trading partner, but the relationship is lopsided: it's mostly Iranian exports to Iraq, to the tune of more than $9 billion. "Hassan Rouhani's recent visit to Iraq is a historic achievement for Iran… the treaties signed, however, harm Iraq's interests — in a clear demonstration of Iran's growing influence in Iraq," said Muhanad Seloom, a research fellow at Exeter University's Arab and Islamic Studies Institute and a former Iraqi government adviser.

Iraqi President Barham Salih Presidency of Iraq | Handout | Anadolu Agency | Getty