– Her friends were rushing to say goodbye. They gathered in the sliver of shade outside her mud hut, next to the pile of bags packed with everything Khairo Hassan had accumulated as a refugee.

“We hope you are safe there,” said a girl who hugged her, while Hassan wept.

In three days, Hassan, 44, would be leaving this sprawling refugee camp for Mogadishu, Somalia, one of the most dangerous cities on the planet, with two of her daughters and her granddaughter. She hated the idea. Every week, it seemed, Islamist extremists there grew more brazen. In October, a truck bomb had killed 512 people.

Hassan was traveling through a United Nations program called “voluntary repatriation,” which provides money to refugees in Kenya who choose to go home. But there was nothing voluntary about her journey to Somalia.

Instead, her return was a sign of how a strained international aid system has failed amid the biggest global refugee crisis since World War II.

The problem started when the U.N., squeezed by growing demands for aid, slashed food rations in this camp of 250,000. That left the refugees little option but to buy food on credit from local markets.

Hassan, a widow, had borrowed $400 over several months to purchase rice, beans, milk and noodles to feed her family. It was an impossible sum in the Dadaab camp, where she made $3 a month selling bananas. Her creditors began to threaten her.

Unwittingly, the U.N. created the only viable way for people like Hassan to pay their debts: by moving to a war zone.

If everything went as planned, before Hassan boarded a plane to Mogadishu, a U.N. official would give her about $150 per family member for their return to Somalia. She would hand it to her creditors.

The U.N. said it was aware that mounting debt could motivate some refugees to return to Somalia. But officials said they had been unaware how prevalent a factor it is.

“This is something we are looking into,” said Denis Kuindje, head of protection at the U.N. High Commissioner for Refugees office in Dadaab.

The voluntary repatriation program started offering the payments in 2016, after Kenyan authorities threatened to shutter Dadaab. Some refugees began to pack up and head for neighboring Somalia, which has suffered near-continuous war since the early 1990s. The U.N. assistance was meant to help them get settled.

But Hassan would start her new life in Somalia with almost nothing. As more people trickled into Hassan’s hut to say goodbye, a man in a shiny red robe slid through the crowd and sat on her bed. His name was Bashir Ali. He was one of the shopkeepers to whom Hassan owed money.

“When are you going to pay me?” he asked. “I told you I will,” she said. “As soon as they give me the money, it will be yours.”

The next day, Hassan and the girls took the first step of their journey to Somalia. Hassan rolled up her thin mattress. She packed a Qur’an.

The family crammed into a taxi. Hassan watched as her corner of the camp disappeared in the rearview mirror.

She had left Somalia in 2010, walking for 16 days, after the Islamist group Al-Shabab had seized control of her town, Dinsoor. Her husband had been shot and killed. One of her daughters had disappeared, leaving her baby.

Hassan didn’t expect to stay long in Dadaab, a string of makeshift encampments in the desert of eastern Kenya. But the situation back home never improved. Last year, Al-Shabab was one of Africa’s deadliest terrorist organizations, killing more than 4,200 people. This year, because of conflict and drought, Somalia reached the brink of famine.

The taxi took them to a bus, and the bus took them to a concrete shelter where Hassan’s family and 27 other refugees were told to wait. They were almost all traveling to Somalia to use the stipend to pay debts.

Adey Ali, a single mother, owed $600, which she spent on food and medicine for her children. Mohammed Usman owed $180. “This is debt-motivated repatriation,” Ali said.

Across Dadaab, the U.N. had posted signs that read, “Return is your choice.” Officials had set up information desks where U.N. officials could determine whether families were going voluntarily. It is a violation of international law to force refugees to return home if their lives are at risk.

Hassan, Ali and other returnees said they mentioned in their repatriation interviews that their debts were the reason they were leaving.

“We know it’s the money on their mind,” said Abdi Fatah Sadik, a repatriation officer with UNHCR in the camp.

The U.N. also acknowledges the devastating effect of the decrease in food rations over the past year. U.N. officials say they instituted the cutbacks because donors such as the United States and European countries have not kept pace with surging demand for aid around the world.

Refugees in Dadaab now receive only 70 percent of their nutritional requirements, according to the U.N. World Food Program. Nearly all of that comes in the form of sorghum, a U.S. donation, which most Somalis do not eat.

To fill the gaps, refugees headed to Dadaab’s markets, run mostly by other refugees. As in Somalia, they can make purchases using a system of credit known as “deen,” based on trust between members of the same clans. Except, eventually, they hit their limits.

Ali said her creditors sent Kenyan police officers to her hut. She spent seven hours in jail until two clan leaders came to bail her out. But first they asked her: “How will you pay your debt?” she recalled.

“I told them, ‘There is only one way. I will enlist in repatriation,’ ’’ she said.

One of the three men to whom Hassan owed money had confronted her months ago, she said. “If you don’t pay me, there’s going to be a fight,” he told her. She signed up for repatriation shortly afterward.

A bus arrived the next morning to take them to their plane. Hassan had never been on a bus or a plane. The bus stopped in front of Dadaab’s airstrip. Hassan and other refugees walked down the steps.

“Stand over there,” a U.N. official said, and the 32 refugees lined up.

Inside, a man at a desk was sitting in front of a pile of white envelopes. Hassan’s name was called. The man reached into one envelope and pulled out $100 bills. He counted them out loud. “Six hundred and 30 dollars,” he said, and Hassan took the envelope from him.

“I wish I could keep it,” she said. But her son and her 28-year-old daughter were still in Dadaab, and they would be hounded about the debt if it wasn’t paid.

About 100 yards away, Hassan could see a crowd of men at the fence. Minutes later, the refugees were at the fence, slipping their money through the barbed wire.

Hassan pushed $200 to one of her creditor’s wives and then gave the rest to her son, who would pay off the remainder of the debt that evening.

“I’m free now,” she said, and lifted both hands in the air in mock triumph.

Three weeks later, back in Mogadishu, Hassan was staying at a red tin house on the edge of the city, in a sprawling displacement camp. Gunshots and small blasts echoed throughout the day and night.

The returnees had formed a committee to lobby the Somali government and the U.N. for more assistance.

“Coming back was a huge mistake,” said Abukar Mohammed, the committee spokesman. Like many other returnees, he was already planning to go back to Dadaab.