Updated

Turkish Prime Minister Ahmet Davutoglu said Saturday that 49 hostages who were seized by Islamic militants in Iraq have been freed and safely returned to Turkey, ending Turkey's most serious hostage crisis.

The hostages were seized from the Turkish Consulate in Mosul, Iraq on June 11, when the Islamic State group overran the city in its surge to seize large swaths of Iraq and Syria.

Their release contrasts with the recent beheadings of two U.S. journalists and a British aid worker by the Islamic State group, but it wasn't immediately clear what Turkey had done to secure the safe release of the hostages.

Deputy Prime Minister Bulent Arinc said the hostages are 49 Turkish consulate employees — 46 Turks and three local Iraqis — including Consul General Ozturk Yilmaz, other diplomats, children and special forces police.

The hostages were released early on Saturday and had arrived in Turkey, Davutoglu told Turkish reporters during a visit to Baku, Azerbaijan. He said he was cutting his visit short to meet them in the province of Sanliurfa, near Turkey's border with Syria.

He didn't say where the release took place, but the arrival of the hostages in Sanliurfa indicates they may have been moved from Iraq to Syria, demonstrating the Islamic State group's cross border reach.

Turkey had been reluctant to join a coalition to defeat the Islamic State group, citing the safety of its 49 kidnapped citizens. The United States had been careful not to push Turkey too hard as it tried to free the hostages.

The extremist group beheaded two U.S. journalists and a British aid worker who were working in Syria as payback for airstrikes that Washington has launched against them in Iraq.

Leaders gave only limited details of the release and it wasn't clear if Turkey had paid ransoms to have the hostages released, or what other method had been used to avoid their hostages meeting a similar fate.

Davutoglu said the release was the result of the intelligence agency's "own methods," and not a "point operation" involving special forces, but didn't elaborate.

"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," Davutoglu said.

Meanwhile, President Recep Tayyip Erdogan said the Turks were freed through "a successful operation."

"I thank the prime minister and his colleagues for this operation which was pre-planned, whose every detail was calculated, which lasted through the night in total secrecy and ended successfully this morning," Erdogan said in a statement.

Thirty-two Turkish truck drivers who were also seized in Mosul on June 6 were released a month later. Turkey did not provide information surrounding their release.