Dozens of hostages captured when Islamic State (Isis) fighters seized the Turkish consulate in Mosul in June have been freed and returned to Turkey.

The 49 hostages were captured in the Iraqi city on 11 June as Isis seized control of large swaths of Iraq and Syria.

Their fate contrasts with the recent beheadings of two US journalists and a British aid worker by the Islamic militants.

The official Anadolu news agency reported that no ransom had been paid and "no conditions were accepted in return for their release". It also said there were five or six previous attempts to secure the hostages' release that had been unsuccessful.

Anadolu said they had been held at eight locations in Mosul, with their whereabouts monitored by drones and other means.

Forty-six of the consulate employees were Turks, along with three Iraqis. They included the consul-general, Ozturk Yilmaz, other diplomats, children and special forces police.

The hostages were released early on Saturday and arrived in Turkey at 5am local time (0300 BST), the Turkish prime minister, Ahmet Davutoglu, said. He returned early from a visit to Azerbaijan to meet them in the province of Sanliurfa, near Turkey's border with Syria, and was bringing them back to Ankara on his plane.

Davutoglu said their release was the result of the Turkish intelligence agency's "own methods", and not a "point operation" involving special forces. He gave no further details.

"After intense efforts that lasted days and weeks, in the early hours, our citizens were handed over to us and we brought them back to our country," he said.

The country's president, Recep Tayyip Erdoğan, said the operation to free the hostages was "pre-planned, whose every detail was calculated, which lasted through the night in total secrecy and ended successfully this morning".

The hostages were one reason why Turkey, a member of Nato, had been reluctant to join a coalition aimed at defeating Isis or to allow its airbases to be used for strikes in Iraq and Syria. The US had been careful not to force the issue while the Turkish government continued negotiations.

Ending Turkey's most serious hostage crisis in its history will be seen as a highlight of Davutoglu's short tenure as prime minister. The former foreign minister has been in the role for less than a month since taking over from Erdoğan in late August.

Thirty-two Turkish lorry drivers who were seized in Mosul on 6 June were released a month later. No details of the negotiations to secure their release have been revealed.