"Today Daesh is fleeing Iraq and this is an admirable success," Khamenei said in reference to the jihadist group as he received Iraqi Prime Minister Haider al-Abadi in Tehran.
But he warned that Iraq "should not trust" the United States, which is leading a coalition fighting IS in Iraq and neighbouring Syria.
Abadi is on a regional tour that started in Saudi Arabia and will include a stop in Kuwait.
He also met Iranian President Hassan Rouhani, as Iraqi forces today pressed an assault on the Old City in western Mosul, the last part of Iraq's second city still held by the jihadists.
More From This Section
He said Iran stands by Iraq in its fight against the jihadists and considers a "victory over terrorism" as its own.
Iraqi commanders said fierce clashes were taking place in the Old City today but admitted that the jihadists were putting up fierce resistance.
"We have many obstacles -- the nature of the land, the nature of the construction, the roads and the civilian population -- all of which make us slow down our work," Staff Lieutenant General Abdulghani al-Assadi told AFP in Iraq.