CNN  — 

A Tunisian doctor who was one of dozens of people killed in the terror attack at Istanbul’s airport had spent months in Turkey trying to rescue his son from ISIS, a friend said Thursday.

Dr. Fathi Bayoudh had been in Turkey for about two and a half months, in an effort to get his son out of Iraq where he was an ISIS medic, longtime family friend Ali Gannoun said.

Bayoudh was at the airport Tuesday waiting on his wife to arrive when he died. She was coming to Turkey after they had received news their son, Anwar, was alive and in Turkish hands, a Turkish official with the Foreign Ministry told CNN.

His son and his daughter-in-law had been detained at the border with Syria after leaving the terror group, the official said.

A look at some of the other victims

“You died as a hero, (Fathi), and you left as a martyr,” Gannoun wrote on Facebook. “You managed to recover your kid. He will live his freedom without you, but he will still be the son of a great man, an exceptional father and an outstanding physician who has never stopped giving his time, his money and his knowledge.”

A friend who served with Bayoudh in the Tunisian military said he had gone on several humanitarian missions and was a professor at the University of Tunis. Retired Col. Sahbi Bachrouch said Bayoudh, who was a major colonel when he died, led the building of a hospital for children during one mission in Somalia.

Months of worry

Gannoun, a professor at the University of Montpellier in France, told CNN that Bayoudh was in “total despair” when his son went missing last year, after telling the family he was going to Switzerland for an internship and taking his wife.

Three months later, the family received a cry for help from their only child: he had joined ISIS and was working as a medic, but wanted to leave.

Maj. Col. Fathi Bayoudh

The son had studied medicine in Mauritania for two years, before dropping out and taking pilot courses.

“He was never in the front lines, never killed anybody,” said Gannoun, adding that the family then proceeded to pay a fortune to smugglers to get him out of Falluja and into safety.

Anwar Bayoudh and his wife went through Syria and arrived in Turkey about five days before the attack at Ataturk Airport. Bayoudh had been communicating with Turkish officials during his time in the country and someone called him to let him know his son was in custody, the Turkish source said.

The Turkish official said the son and wife had turned themselves over to Turkish authorities.

The family was in negotiations with the Turkish and Tunisian authorities.

Bayoudh and his wife, also a doctor, were hoping to complete some paperwork and take their son back to Tunis. They were going to go to a village near the border to pick up the son and daughter-in-law, the Turkish official said.

TAP, a news agency based in Tunis, said the son and wife will be handed over to Tunisian authorities soon.

CNN’s Steve Almasy contributed to this report.