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.
dtMGM7l2DvUThe US House Ethics Committee has voted to release its report on former Republican Representative…
ABC News has agreed to pay $15 million to President-elect Donald Trump to settle a…
South Korea’s parliament has voted to impeach President Yoon Suk Yeol over his failed attempt…
Israeli war planes have carried out more than 100 air strikes in Syria on December…
President-elect Donald Trump has threatened to impose 100% tariffs on the BRICS countries if they…
Syrian troops have withdrawn from the city of Aleppo following an offensive by rebels opposed…