He and his family had tried for 17 months to make it in Greece, and Kamal Mahmood said he felt “shame” for how badly it had gone.

Back home in Iraq, he’d been a doctor; here, he was recognized only as a migrant. He and his wife had become destitute. The family slept in tents and shelters — until they ultimately decided to return to the country they’d once paid $12,000 to flee.

“Don’t lose this, okay?” a United Nations migration officer said at the airport in Athens, handing Mahmood a packet of documents. “These are your tickets up to your arrival in Iraq.”

“Got it,” Mahmood, 44, said quietly, taking the tickets, along with a temporary passport that listed his wife and four children and said “one way” on the front.

He and his family were returning as part of a program, funded by Greece and the European Union, that has become one of the most significant pathways of reverse migration from Europe. Through that program, about 16,900 people have made the trip back to Africa, Asia or the Middle East over the past three years. The flow is one of the consequences of E.U. countries having tightened borders, imposed stricter requirements for legal status or otherwise made themselves inhospitable.

Many migrants now feel coming to Europe was a mistake.

In some parts of the continent, people who feel this way have few options, particularly if they have no money to go home on their own. Even migrants rejected for asylum are rarely forcibly deported.

But Greece is trying to offer a way out with what amounts to a deportation system on a voluntary basis. Some people opt to go home because they have faced initial rejections in their bids to qualify as refugees. Some have fallen into under-the-table agriculture jobs with illegally low wages. Others are simply fed up with being stuck in Greece’s notorious tent camps, which human rights groups say are intentionally squalid and overcrowded.

Those who leave are “people who have had enough,” said Gianluca Rocco, chief of the International Organization for Migration (IOM) mission in Greece, which operates the returns program.

Groups that focus on migration say IOM provides an otherwise-lacking last resort for migrants, who are given travel documents, commercial plane tickets and several hundred euros in cash — plus, for some, another 1,500 euros they can use for job placement or to start businesses back home.

At a refu­gee camp north of Athens, families seeking asylum live in makeshift housing, with tarps thrown over plywood. (Myrto Papadopoulos for The Washington Post)

But the decision to leave also highlights Europe’s failure to accommodate those who came seeking refuge or opportunity — a group that includes the Mahmoods, who opted to return to the Iraqi region of Kurdistan even before the conclusion of their asylum case.

Kamal Mahmood slept for two hours on his last night in Europe, thinking about the many reasons they’d come to Greece in the first place. Their eldest son had died of leukemia — a loss Mahmood blamed partly on Iraq’s health-care system. In the aftermath, Mahmood’s wife, heartsick, rarely left their home. Around the same time, Mahmood was demoted from manager at the hospital where he worked, because of what he described as a strained relationship with the Kurdish political party that influenced management decisions.

The family figured Europe would be a fresh start.

“It was a way to forget the pain,” Mahmood said.

What they hadn’t known was that their new home in Greece would be an isolated camp, away from easy job access, where knife fights sometimes broke out at night. Once or twice the family had to relocate their tent outside the gates for safety.

The children could attend school, but only in the afternoon, after the Greek kids had left, in foreigners-only classrooms that grouped together many ages and languages.

A Syrian child holds a plate with a pomegranate, his afternoon snack at a refugee camp. (Myrto Papadopoulos for The Washington Post)

Many of those in the pipeline to go home, including the Mahmoods, had arrived in Europe illegally and struggled without documents.

Sheharyar Sultan, 24, a pharmacist in Pakistan, found himself in Greece picking oranges for 20 euros per day.

Mamdouh Awad, 24, of Morocco, spent the bulk of his time in Greece at a migrant camp on the island of Lesbos, where he said people drank alcohol during winter nights “just to stay warm.”

The Mahour family from Iran twice tried to move farther north through Europe with fake passports; they were stopped both times and then rejected for asylum in Greece. Their 17-year-old daughter, who’d become a theater performer in Athens, has tattoos and piercings. Their 1½ -year-old son, born in Greece, has a Western name, Nelson. They bridled at the idea of returning to a more restrictive country where they could face persecution for their atheist beliefs.

Habib Mahour and his family decided to return to Iran after their asylum applications were rejected in Greece. (Myrto Papadopoulos for The Washington Post)

“When I go back to Iran, I don’t know if I’ll be fired or in prison,” said Habib Mahour, 42, a ponytailed construction worker. “But I know I can’t get papers here. I prefer to face whatever may come. We are very tired here in Greece.”

Among E.U. nations, Greece perhaps best illustrates what leaves migrants feeling stuck. The country is the purported gateway to Europe for those fleeing through Turkey; few who arrive actually want to stay in Greece. At the height of the continent’s migration surge in 2015, asylum seekers who arrived in Greece quickly moved north, crossing through Balkan countries toward wealthier nations such as Germany and Sweden. But Greece’s neighbors have since clamped down, closing routes that once provided passageway out of the country. More than 1 million migrants have arrived in Greece since 2015. During that same period, 240,000 have applied for asylum.

One option for Greece is sending migrants back to Turkey. A 6 billion euro deal in 2016 between the E.U. and Turkey was supposed to open the door for massive returns — but it hasn’t worked out. Vulnerable migrants still have the right to seek asylum in Greece, meaning they can stay in the country during a multiyear process. Since the deal was reached, more than 100,000 migrants have arrived from Turkey to Greece. Fewer than 2,000 have been returned.

Greece’s new conservative government says it intends to step up pressure on Turkey. Prime Minister Kyriakos Mitsotakis says most of the people now coming to Greece have “the profile of economic migrants, not refugees” who merit protection.

Whatever their status, the arriving migrants languish in what is widely viewed as the most the fetid conditions in Europe. Asylum seekers are housed in tents and shipping containers on island centers, surrounded by overflowing garbage and sewage. Advocates say Greece has had plenty of time to improve the camps but has refused to do so, as a way to deter people from making the trip.

Some families living in refu­gee camps have planted vegetables, such as okra, to supplement their diets. (Myrto Papadopoulos for The Washington Post)
Nazzanin Mahour, 17, acquired her tattoos in refugee camps in Greece. (Myrto Papadopoulos for The Washington Post)

But deterrence hasn’t worked. Arrivals from Turkey are again on the rise, and 31,000 migrants are being housed in facilities designed for 6,000, according to government data. In September at the largest island camp — Moria, a former military barracks — a fire killed a woman from Afghanistan and led to rioting and demonstrations, with protest signs reading, “Moria is hell.”

It is at those camps, and at other, better-equipped facilities for migrants on the Greek mainland, where the IOM tries to spread the word about the possibility of going home.

Some people, based on U.N. guidelines, are ineligible for the program; migrants aren’t returned to Syria, Palestinian territories, Yemen, or other regions or countries deemed too dangerous. In Greece, people from those parts of the world almost always win asylum anyway. It is the others — from Afghanistan, Iraq and Pakistan — who are likelier to return home, and they line up every morning outside the IOM headquarters in Athens to apply.

While awaiting their travel documents, those without money are allowed to stay at a shelter in central Athens — a facility run by the IOM and converted from an abandoned office building — where the Mahours from Iran stayed in room 108, and the Mahmoods from Iraqi Kurdistan stayed in room 106.

Muhammad Zubair, 28, waits for the IOM representative who will accompany him to his departure gate at the Athens airport. (Myrto Papadopoulos for The Washington Post)

“It’s going to be a long day,” Kamal Mahmood told his children on their last morning in that room. They arrived at the Athens airport with four duffel bags, two worn suitcases, a stroller and a grocery bag packed with belongings.

As they waited to check in, Chrakhan Mahmood, 19, scrolled through Facebook, looking at photos of fighting in Kurdish areas of Syria, across the border from Iraq.

“Look,” she said, holding up a photo of dead bodies.

As far as Kamal Mahmood was concerned, Kurds had always been in limbo. He didn’t think war would come to his part of Iraq. But Syrian refugees, he said, would probably arrive. That was just one of the variables. How would his children adjust? Would he get his old job back?

“If I could find something for my children here, I would stay,” he said. “But I can’t. So maybe going back is better.”

He held up his phone, like a seesaw, as if weighing Greece on one end, Iraqi Kurdistan on the other.

“It is bad on both sides,” he said, and soon his family was at the gate and in the air, arriving at 2:35 a.m. to restart their lives in Iraqi Kurdistan — a place that, for now, seemed slightly less bad than Greece.

Elinda Labropoulou contributed to this report.