Dozens of Turkish hostages seized by Islamic State (IS) in the north Iraqi city of Mosul in June are now back in Turkey, PM Ahmet Davutoglu says.
The 49 hostages included diplomats and their families as well as soldiers.
They were seized from Turkey's consulate after IS militants seized Mosul in a rapid advance in June.
Turkey has refused direct involvement in the military campaign against IS partly because of fears over the hostages' safety.
Mr Davutoglu said that the hostages were all in good health and that they were released early on Saturday.
They were being taken to the southern Turkish city of Sanliurfa by the Turkish intelligence agency, he added.
"From my heart, I thank the families who maintained their dignity" he said on Twitter.
Mr Davutoglu will cut short a visit to Azerbaijan to meet the released hostages.
IS 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 jihadist group in Iraq since mid-August.
French jets carried out their first strikes on Friday, hitting an IS depot in north-eastern Iraq.