"Congratulations to brave people and Government of Iraq upon liberation of Mosul," Foreign Minister Mohammad Javad Zarif wrote late Sunday in a tweet.
"When Iraqis join hands, no limits to what they can achieve."
Prime Minister Haider al-Abadi was in Mosul Sunday, officially marking the end of a difficult campaign to retake the city, where IS declared its self-styled caliphate three years ago.
Other Iranian officials were also quick to welcome the victory, Iraq's biggest yet against the terrorists.
"The government, armed forces and the brave nation of Islamic Iran... are prepared to offer aid to the displaced and injured in the war and help rebuild the cities and vital infrastructure in the country," official news agency IRNA quoted Shamkhani as saying.
Defense Minister Hossein Dehghan and the chief of staff of Iran's armed forces, Major General Mohammad Bagheri, also congratulated Abadi, saying they were ready to boost defence and security ties with Baghdad.