ANKARA (Reuters) - Iran’s supreme leader, Ayatollah Ali Khamenei, told Iraq’s U.S.-backed prime minister on Thursday that he should not rely on the United States in the fight against Islamic State, seeking to drive a wedge between Washington and one of its close allies.

Slideshow ( 6 images )

“Unity was the most important factor in your gains against terrorists and their supporters,” Khamenei told the visiting Prime Minister Haidar al-Abadi, according to state TV. “Don’t trust America ... It will harm you in the future.”

Iraq is one of the only countries in the world that is closely allied to both the United States and Iran. Both countries have armed and trained pro-government forces in Iraq in the battle against Islamic State militants.

The United States, which installed the Shi’ite-led government in Baghdad after toppling Saddam Hussein in 2003, now has 5,000 troops in Iraq and provides air support, training and weapons to the Iraqi army. Iran, the predominant Shi’ite power in the Middle East, funds and trains Iraqi Shi’ite paramilitaries known as Popular Mobilisation, which fight alongside government troops.

For years, Baghdad has carefully avoided antagonising either Washington or Tehran. But a confrontation between the Iraqi central government and its Kurdish minority in recent weeks has threatened to tip the balance in Iran’s favour. The Kurds are also funded and trained by Washington which has considered them allies for decades.

After the Kurds staged a referendum on independence last month, Abadi responded by sending his troops to swiftly seize territory from Kurdish forces.

This week, Abadi rebuked U.S. Secretary of State Rex Tillerson for demanding he send Iranian fighters in pro-government Shi’ite militia “home”. Abadi’s office issued a statement saying no country should give orders to Iraq and calling the paramilitaries “patriots”.

He has since travelled to both Turkey and Iran to seek support for his hard line towards the Kurds.

The Kurdish regional government proposed on Wednesday an immediate ceasefire, a suspension of the result of last month’s Kurdish independence vote and “starting an open dialogue with the federal government based on the Iraqi Constitution”.

The offer was rejected by Abadi’s government, which said the independence referendum result must be annulled, rather than merely suspended, as a pre-condition to any talks.

“We will preserve Iraq’s unity and will never allow any secession,” Iran’s state news agency IRNA quoted Abadi as saying during his meeting with Khamenei.