The Iraqi women who escaped from ISIS had their sights set on a new life in Germany. Where that was, they weren’t sure, but it was far away, they heard, and Dr. Mirza would take them there.

His name was invoked all around the city of Duhok, in northern Iraq, from the dusty camps to the unfinished concrete houses where survivors had been sheltering since escaping bondage at the hands of ISIS fighters.

None of the women—who were spirited to safety by smugglers or who daringly ran from their ISIS captors on their own—could explain how they were getting to Germany without money or passports, or who exactly Dr. Mirza even was. (“An important man,” one said. “A friend to the Yazidis,” said another.)

The women were all Yazidis, members of the religious minority that had borne the brunt of the ISIS rampage in the summer of 2014, with the militants massacring thousands of men and taking thousands more women and children as slaves. Now, after escaping death and captivity, they were hoping that the man known simply to them as Dr. Mirza might fly them from this stark brown landscape, which they had never left, and to a new continent where ISIS could never harm them again.

Over the course of nearly a year, beginning in March 2015, Mirza Dinnayi—a soft-spoken and bespectacled Yazidi activist and humanitarian—did just that.

By early last year, Dinnayi had quietly helped track down, vet, and transport more than 1,000 survivors of ISIS captivity—mostly women, who had been kept as sex slaves, and their children—to Germany. The unprecedented rescue and asylum program was born of an unprecedented crisis: the genocide of the Yazidis at the hands of ISIS.

The details of that summertime attack on civilians in Iraq’s remote Sinjar region are now well-known. Survivors have told and retold the story of how the notorious jihadists, then at their prime, marched Yazidi men off to the slaughter before busing some 5,000 other civilians—most of them women and children—to ISIS slave markets, where they were bartered and sold.

Days after the violence began, President Barack Obama authorized airstrikes against ISIS in Iraq, the start of the U.S. war on the militants that continues today. But even as the U.S. and its allies mobilized to take on the jihadists, Dinnayi understood that the scale of the crisis was beyond anything that could be solved by military support alone.

A Yazidi himself, he had moved to Germany in 1994 to escape persecution and study medicine. At the time, the Yazidis had been suffering persecution for years at the hands of the Saddam Hussein regime. When, after Hussein was toppled, Dinnayi returned to Iraq to advise the country’s then-president, he quickly saw his hopes for a new era fade.

Extremists were targeting the Yazidis in attacks, and in 2007 ISIS’s predecessors killed hundreds of Yazidis in a coordinated bombing, the deadliest attack on civilians in the Iraq War. So he co-founded a nonprofit that flies Iraqi victims of terrorism to Germany for medical treatment. The 2014 ISIS attack convinced him that the Yazidis, who number around 600,000 in Iraq, could no longer survive in their homeland. They needed asylum.

Dinnayi delivered this message to anyone he could. Even after breaking his leg in a helicopter crash during a mission to rescue civilians fleeing ISIS’s advance, he appeared on television in a wheelchair to repeat his demands: more aid, more military support, genocide recognition and, critically, some sort of asylum for survivors in Europe or the United States.

His leg in a cast, Dinnayi took his message to Israel, Switzerland, and throughout Germany. Waves of other Yazidis had also migrated to Germany over the years, making it home to more Yazidis than anywhere in the world outside of Iraq. “The whole Yazidi community in Germany was very active in encouraging the German government to do something,” he said over a coffee at an Istanbul airport during one of his regular layovers last year.

He credits the country’s largest Yazidi organization, the Central Council of Yazidis, for finally finding one politician willing to help.

Winfried Kretschmann, who heads the wealthy German state of Baden-Württemberg, decided to open its doors. “He is a very human man,” Dinnayi said. “He saw [what was happening] and said, ‘We should do something for these people.’”

No state in Germany had ever run its own refugee program, and it wasn’t clear if it was legal. “There was an option for [a state-run humanitarian program] in the German law, but it had never been used,” said Dr. Michael Blume, the head of Baden-Württemberg’s department of churches, religion and integration, whom Kretschmann asked to lead the project. Eventually, he said, federal authorities told the state it could “give it a try.”

Despite creeping anti-refugee sentiment, the shock of ISIS’ systematic sexual violence evoked a deep emotional response across Germany’s political spectrum. Blume said he encountered no resistance to the rescue program when he began discussing it with local leaders and quietly assembling a team.

Blume brought on Dinnayi to handle recruitment in Iraq and also tapped a Kurdish-German psychologist, Jan Ilhan Kizilhan, an expert in trauma and Middle Eastern cultures.

They quickly agreed to focus on psychotherapy and rehabilitation. “It wouldn’t make sense to bring traumatized people here and then not help them psychologically or medically,” Blume said.

By the time the team began to hash out details of the pilot program in late 2014, a steady stream of Yazidis had escaped captivity in precarious physical and psychological shape. Some had become pregnant as the result of rape. Others were so distraught by what they had suffered that they committed suicide. Blume and his colleagues feared that the longer the victims went without treatment, the more likely they’d be to lose their lives.

“The Yazidis told us nobody can help them. There were just too many [victims] and only about 25 psychologists in northern Iraq,” Blume said. “The initial goal was to evacuate and stabilize those that wouldn’t survive on their own.”

The state set aside 95 million euros, less than 1 percent of its annual budget, to cover the cost of selecting, processing, and transporting 1,000 survivors to Germany and providing two years of care and therapy for them after they arrived.

Once in Baden-Württemberg, the participants would receive the same financial support as other refugees in the state, including a monthly stipend, housing, and free medical and psychological care. They would also be entitled to special privileges such as the right to travel abroad and even back to Iraq to visit family. And they would be eligible for permanent residency. “We wanted a mix between an emergency program, where you help people and then they go back, and a resettlement program, where they come and stay,” Blume explained, adding that his team wanted to empower participants to plot their own futures.

Over the next 15 months, Blume and his team divided their time between Germany, where they prepared for the group’s arrival, and Iraq, where they began the daunting process of selection.

To qualify for the program, Kizilhan had to conclude that, as a result of their captivity, candidates were suffering from a medical or psychological illness that could be better treated in Germany than in Iraq.

The team also decided that while they wouldn’t lie to the press, they wouldn’t go out of their way to publicize the operation, either. They feared for their own safety as well as the safety of the escapees, who might still be targeted by ISIS.

Yet back in Duhok, as Dinnayi opened an unmarked office and set out to find and fetch potential candidates, word quickly spread that Dr. Mirza was a man who could get you to Germany. With so much desperation in the region, it wasn’t long before the bribery offers began rolling in. Some people falsely claimed to be ISIS victims. “There were different ways that people tried to come into this project, but it was not successful, because we were very careful, and because the Yazidi community is very small,” Dinnayi said. “Everybody knows each other, so it is not easy to lie.”

Meanwhile, Kizilhan sat down with each of the 1,400 legitimate ISIS victims sent his way for a psychological evaluation that determined who could continue on to Germany.

It was dark work. Kizilhan said that although he has experience with rape victims from the Rwandan and Bosnian genocides, hearing the testimony of ISIS’s brutality took a unique toll on him.

“As a father of two girls, I was always asking myself how a human can do such cruelty,” he said. “Of course, as a psychologist and as a scientist, I have a lot of theories to explain why people become terrorists or how they can be so evil. But when you are sitting in front of an 8-year-old girl who is telling you she was raped, six, seven times a day for months, those theories are not really helpful to me, as a human.”

Among the cases he approved were the 8-year-old rape victim; six boys forced to serve as child soldiers; an 18-year-old who lifted giant stones in captivity to force a miscarriage after becoming pregnant as the result of rape; and a 16-year-old who developed psychosis and lit herself on fire weeks after escaping her tormentors. She believed that they were still pursuing her, even in the relative safety of her family’s tent, and wanted to make herself ugly so they would finally leave her alone.

The work took a toll on the other team members as well. Blume spent more than a third of the year away from his wife and young children, working about 16 hours a day, often agonizing over the question of who would be selected and who would be left behind. “That was the hardest part. I’ve never had a year that was so hard but also so meaningful,” he said.

Dinnayi, witness to the destruction of his own community, says that he too was traumatized by the work. “I couldn’t sleep in the beginning. I was crying several times a day when I was hearing the stories of the victims. They will stay with me for all my life,” he said. “When I remember some of their stories and I see their pictures in front of my eyes I say, ‘how could such things happen in the 21st century?’”

In the end, the team wound up approving 1,100 survivors—mostly Yazidis, but also some Christians. One thousand were settled in Baden-Württemberg, while the remaining 100 were divided between the states of Lower Saxony and Schleswig-Holstein. The majority accepted to the pilot program were minors, and 96 percent of the entire group was diagnosed with post-traumatic stress disorder.

Actually getting the survivors to Germany was a bureaucratic feat, led by Dinnayi, who had to wrangle passports for each of them in a country that requires male relatives to be present when important documents are ordered or renewed. “About 90 percent of them lost their husbands and fathers,” Dinnayi said. “We needed the court to issue special certificates for mothers to say that the father isn’t here. It was very difficult.”

The team, with the help of the International Organization for Migration, also had to quietly get the group to the Erbil airport in Iraq’s semiautonomous Kurdish region. They worried that ISIS fighters could doom the project if they managed to attack a convoy of escapees and warned participants not to share information about their locations on social media. “We worked closely with the Kurdish government and the Kurdish armed forces. We had armed Kurdish guards, we changed hotels, routes, license plates, and changed our internet devices so ISIS wouldn’t be able to track us,” Blume said. “The fear was that [ISIS] would see these women and children as their property and want to target them for that reason, but also because they were witnesses.”

On their way to the airport, Blume requested that each convoy stop in the valley of Lalish, a burst of green in the brown landscape that’s home to the most holy sanctuary in the Yazidi religion. Once there, he hoped Yazidi religious leaders would publicly bless the women and children to send a message to them—and to all Iraqis—that they hadn’t done anything wrong. “In the beginning, some were not even accepted by their own families because they were seen as defiled,” Blume said. “Our shared message was clear: The only ones that lost their honor were the attackers.”

On a hot May morning in 2015, Dinnayi and Blume were sweating in their suits as they ushered the latest batch of survivors from the lobby of a Duhok hotel onto a pair of coach buses idling outside. After a scenic hour-long ride, the buses deposited them in Lalish where the spiritual leader of the Yazidis—a white-bearded, white-robed man called Baba Sheikh—awaited them in a shaded courtyard at the arched entranceway to the ancient sanctuary.

The young women and teenaged girls, some ponytailed, and others wearing dark headscarves to mourn the loss of loved ones, crowded into the courtyard and strained their necks to catch a glimpse Baba Sheikh and record his message on their smart phones. “There are 120,000 Yazidis in Germany, so don’t feel like you are a stranger there,” he told them. “I will be praying for you when you go.”

Then the women and girls filed into the darkness of the sanctuary and prayed, methodically circling a sacred tomb and splashing themselves with spring water believed to have healing powers. Some giggled and posed for selfies.

The weight of their impending departure seemed to hit them only as they made their way back to the buses. All had to leave family behind. Sobbing into the arms of their loved ones, they said goodbye. As the buses wound out of the valley and on toward the airport, some reached their arms out the window to take photos. Others simply looked back on their families and ancestral homeland, possibly for the last time.

Reporting for this article was funded by the Pulitzer Center on Crisis Reporting. This is the first in a three-part series on a rescue program for ISIS slaves.