Turkey’s Prime Minister Ahmet Davutoglu said the 49 had been taken to the southern city of Sanliurfa by the Turkish intelligence agency.
Details are unclear but President Recep Tayyip Erdogan said it had been a “detailed and secret operation”.
The hostages were seized after ISIS militants overran Mosul in a rapid advance in June.
Turkey has refused direct involvement in the military campaign against ISIS partly because of fears over the hostages’ safety.
Deputy PM Bulent Arinc said the 49 hostages were employees from the consulate – 46 Turks and three local Iraqis – and included Consul General Ozturk Yilmaz, other diplomats, children and special forces police.
Ahmet Davutoglu said they were all in good health and that they were released early on Saturday.
“I am sharing joyful news which as a nation we have been waiting for,” he said.
“In the early hours our citizens were handed over to us and we brought them back to our country. They have crossed into Turkey and I am on my way to see them.”
Ahmet Davutoglu was cutting short a visit to Azerbaijan to meet the released hostages.
He did not give details on the circumstances of their release but broadcaster NTV reported that Turkey had not paid a ransom. It did not say how it obtained the information.
More than 30 Turkish truck drivers, who were also seized in Mosul in June, were freed a month later but details of their release were not made public.
ISIS has seized large areas of Iraq and Syria. Estimates say the group could have up to 30,000 fighters.
The US has carried out more than 170 air strikes against the jihadists in Iraq since mid-August, supporting Iraqi government and Kurdish ground troops.
French jets carried out their first strikes on Friday, hitting an ISIS depot in north-eastern Iraq.
Also on September 19, Turkey opened a stretch of its south-eastern border to thousands of Syrian Kurds fleeing an ISIS advance.
Turkish troops had earlier blocked them from crossing, triggering angry protests from Turkish Kurds in the border village of Dikemetas.
Turkey has been under pressure from Western countries to tighten up its borders with Syria and Iraq and to stem the flow of foreign fighters joining the militants.
More than 847,000 Syrian refugees have crossed into Turkey since the uprising against Syrian President Bashar al-Assad began in 2011.
More than 30 nations have joined a US-led coalition to take on ISIS militants, but Turkey has said it will only allow humanitarian and logistical operations from a NATO air base on its soil.
Syria and Iran have been excluded from the coalition.
dtMGM7l2DvUQuincy Jones, the celebrated musician and producer who worked with Michael Jackson, Frank Sinatra, Ray…
Misleading allegations, rumours and outright lies about voting and fraud are flooding online spaces in…
At least 158 people have died in Spain's worst flooding disaster in generations. On October…
Google has been fined two undecillion (a two followed by 36 zeroes) roubles by a…
Embarking on a home remodel is an exciting journey, promising enhanced comfort, increased property value,…
The US presidential candidates continued to campaign across key swing states on October 20. Footage…