Saudi Arabia, with the Islamic State on the ropes in Iraq, is forging ties to Iraqi Shiite leaders and offering to help fund reconstruction of Mosul and other predominantly Sunni Muslim cities that were devastated in the military campaign against the jihadist group.

The Saudi outreach to Iraqi Prime Minister Haider al-Abadi and controversial Shiite scholar, politician and militia leader Moqtada al-Sadr, who last week held rare talks in Jeddah with Crown Prince Mohammed bin Salman, aims to contain significant Iranian influence in Iraq. Mr. Al-Sadr is widely seen as having balanced his strong sense of nationalism with his relations with Iran. It was his first visit to the kingdom in more than a decade.

Mr. Al-Sadr’s visit was a far cry from the days not so long ago when as a firebrand he railed against the kingdom, prompting an Iraqi poet to declare that “with Moqtada’s help we will destroy Saudi Arabia.”

Mr. Al-Sadr, who has criticized powerful Iranian-sponsored Shiite militias fighting the Islamic State alongside the Iraqi army as well as Iran’s backing of Syrian President Bashar al-Assad, was preceded by Mr. Al-Abadi who was received in the kingdom in June despite having voiced days before his visit opposition to the two-month old Saudi-UAE led diplomatic and economic boycott of Qatar.

Rivalry with Iran is one of the core issues in the Gulf crisis. The Saudi-UAE alliance has demanded that Qatar curtail its relations with Iran, with which it shares the world’s largest gas field.

The Saudi outreach also signals a rare Saudi recognition that Iranian influence is a fact in a vicious proxy war that so far has been largely fought by the kingdom as a zero-sum-game. The proxy war prompted Saudi Arabia’s ill-fated military intervention in Yemen that has brought Yemen to the brink of the abyss as it battles famine and epidemics, aggravated Syria’s brutal civil war, and sparked sectarian tensions across the Muslim world.

Ibrahim al-Marie, a retired Saudi colonel and Riyadh-based security analyst, voiced Saudi expectations of its outreach when he noted that “the significant improvement in Saudi-Iraqi relations, official and non-official, doesn’t mean that Iran’s domination of Iraq has decreased or will decrease. Dealing with all political currents in the Arab world is expected from a country of the kingdom’s size and stature.”

The Saudi outreach, despite Saudi Arabia’s designation of Iranian-backed Lebanese militia Hezbollah as a terrorist organization, constitutes the second time in six months that the kingdom has opted for engagement rather than confrontation.

Saudi Arabia in February reversed its cancellation of $3 billion in military aid to Lebanon, where Hezbollah is one of the country’s foremost political forces and part of the government; appointed a new ambassador; rescinded its advice to Saudis not to visit Lebanon, a popular Saudi tourism destination; increased flights to Beirut by its national carrier; and welcomed Lebanese President Michel Aoun, a Christian ally of Hezbollah, on a visit to the kingdom.

Prince Mohmmed reached out to Mr. Al-Sadr as the kingdom’s security forces were cracking down on activists in the predominantly Shiite, oil-rich Eastern Province. The Saudi interior ministry reported earlier this week that a police officer was killed and six others injured when their patrol was attacked in the town of Al Awamiyah. Al Awamiyah was home to Sheikh Nimr al-Nimr, the Shia scholar whose execution in early 2016 sparked a rupture in Saudi-Iranian diplomatic relations.

Canada, which sold $15 billion worth of armoured vehicles to Saudi Arabia, last week launched an investigation into claims that they had been employed in crackdowns on Shiites. The investigation was based on videos released by Saudi human rights activists that purported to show the use of Canadian vehicles in past crackdowns in the Eastern Province rather than the current operation in Al Awamiyah.

Saudi engagement with Iraqi leaders comes in advance of Iraqi provincial and parliamentary elections scheduled for next year. Mr. Al-Sadr’s visit to Jeddah took on added significance because of his opposition to Mr. Al-Abadi’s rival, former Iraqi prime minister Nouri al-Maliki, who is widely seen as a major Iranian asset. The visit raised questions of what role Mr. Al-Sadr may want to play in countering Iranian influence in cooperation with the kingdom.

Messrs. Al-Sadr and Al-Abadi hope that Saudi Arabia will not only help in funding reconstruction of predominantly Sunni Muslim cities that have been left in ruins by the campaign against the Islamic State, but also in building bridges to a community that feels that it has been marginalized since the 2003 overthrow of Saddam Hussein’s minority Sunni regime. They believe that Saudi Arabia will be able to leverage not only its financial muscle but also the fact that many Iraqi Sunni tribes share a common lineage with Saudi clans.

Mosul, Iraq’s second largest city prior to its takeover by the Islamic State in 2014, has been virtually destroyed. Its infrastructure will have to be rebuilt from scratch at an estimated cost of tens of billions of dollars. Rebuilding other cities ravaged by the anti-Islamic State campaign has been slow to get off the ground.

Some optimists suggest that there may be more to Saudi moves. They hold out the possibility that Prince Mohammed is looking for a back channel to Iran, a role Mr. Al-Sadr could fulfil as one of the few Iraqi Shiite politicians who has reasonable relations with both the Islamic republic and the kingdom. More likely, however, Prince Mohammed sees an opportunity to exploit differences within the Iraqi Shiite community towards Iran and the government’s need of help in forging bridges to its Sunni citizens.

“One thing is for sure. The Saudis did not invite a major Iraqi Shiite cleric to Jeddah just to inquire after his health,” quipped Middle East scholar Juan Cole.