BAGHDAD — From financing the expansion of the vast courtyards that lead into the Shiite shrines of the holy city of Najaf, to ensuring that a Tehran-friendly candidate gets the job of interior minister, Iran’s role in Iraq keeps growing.

President Hassan Rouhani of Iran arrived in Baghdad on Monday for a visit to a place that his country has shaped in ways big and small over the past several years. Iran was the real winner of last year’s parliamentary elections in Iraq: The parties linked to the paramilitary Popular Mobilization Forces, most of them with ties to Tehran, emerged as the kingmakers.

“Iran is a small body with a big brain, and the United States is a big body with a small brain,” said Mahmoud al-Mashhadani, a Sunni Muslim who was a former speaker of the Iraqi Parliament, trying to explain how Iran seemed to have gained the upper hand in Iraq.

Adnan al-Zurfi, a Shiite member of the Iraqi Parliament who has lived in the United States, put it succinctly.