KHARTOUM, Sudan — He crossed the open plains of the border on foot more than a year ago.

Once inside Sudan, he was picked up by border patrol officers and sent to a crowded, decades-old refugee camp. He stayed there for one month. From there, after paying the equivalent of $500, he was smuggled on a pickup, along with 17 others, into the capital, where he worked for months in a cafeteria and tried lying low, or as he put it, “cooling it.”

Then he got ready for his next move: Libya.

“I know it is dangerous, but I am forced to,” said a nervous Yusuf Muhammad, 27, an Eritrean migrant in Khartoum. “I have no choice. I want to go to Europe or America.”

Thousands of migrants and refugees, especially from neighboring Eritrea and Ethiopia, come to Sudan every year. Many arrive with plans to earn some money and to connect with smuggling networks, making Khartoum a major launching pad for migrants heading to the Mediterranean and, ultimately, to Europe.

“There are people who come here with the sole purpose of moving, stay for a few months, work, gather money and go,” said Renata Bernardo, project coordinator at the International Organization for Migration in Khartoum.

The migrants and refugees say they are escaping harsh political and economic realities in their own countries, and sometimes both. In Eritrea, torture, extrajudicial executions, disappearances, forced labor and sexual violence are widespread and systematic, according to the United Nations, along with an indefinite military conscription system.

“Life is really hard in Eritrea, no freedom, no work,” Mr. Muhammad said.

Ethiopia boasts a fast-growing economy, but the benefits of this growth are not felt widely through the populous country, with more than two-thirds of the population living in severe poverty, according to the United Nations Development Program. The government is widely criticized for political repression and rights abuses.

Tasew Taero, 33, said he was a university student in Ethiopia, from the region of Oromia. Political unrest in his area brought on a security crackdown. He was arrested and tortured, despite not being involved in any activism, he said, so he decided to leave.

After traveling for a month and paying smugglers $350, he made it to Khartoum two years ago. Now he is waiting for an opportunity to go to Libya.

“If I get a chance, I will go,” he said. “When I have the money.”

Even after two years, some may consider him a recent migrant here. For decades, eastern Sudan has hosted refugees from both countries. Eritrea’s decades-long war of independence brought tens of thousands here, as did political strife in parts of Ethiopia. While many have accustomed themselves to a challenging life in Sudan, many of their children now are looking for better opportunities elsewhere.

“Sudan has always been at the crossroads of migration routes, for refugees and migrants,” said Angela Li Rosi, deputy representative of the United Nations High Commission for Refugees in Sudan.

Ghere Abraham, 45, is an Eritrean refugee who has lived in Sudan for nearly 30 years. A video of Islamic State fighters in Libya slaughtering Ethiopian and Eritrean migrants this year sickened him. Two of the people killed in the video had lived in his neighborhood in Khartoum.

The April evening the video was released, he went to the neighborhood church where condolences were being offered. It also reminded him of what could have happened to his eldest daughter, who tried recently to cross the Sahara to the Mediterranean with hopes of reaching Europe. He managed to stop her just in time, after threatening to kill the broker responsible for putting her in contact with smugglers.

“I cried when I saw her,” he said.

His daughter, Hiweit Abraham, 20, spoke grudgingly about the events, with no regrets about making the attempt to leave.

“I have no life, no respect, there’s nothing I can do here,” she said. “Because I am a refugee.”

Mustafa Ismail Abdalla, 25, grew up in Sudan. His father was a political activist with the Oromo Liberation Front, an Ethiopian rebel group labeled a terrorist organization by the Ethiopian government. But his life he is about working: He has been doing it since he was 8 and juggles three jobs today.

“Some of my friends went a few months ago and are in France now,” he said. “I just need a little more money and I will go.”

The high season for departures is February to October, when the waters along the Mediterranean tend to be lower, migrants here say. The smugglers have waiting lists, and many who make the trip face the dangers of detention, beatings, abuse and sexual assault in the desert.

While most of the migrants heading to Libya are from Eritrea and Ethiopia, increasing numbers are Sudanese, especially from Darfur, as well as Syrians and even Pakistanis and Nigerians who travel to the Mediterranean via Sudan. Here, they contact the smugglers through brokers, who take off into the desert from meeting points throughout the capital that shift to avoid detection.

“It’s around $1,200 to get to Libya,” Ali Ibrahim, a smuggler, said. “Prices go up and down if there are problems.”

From the outskirts of Khartoum, four-by-four pickups with 20 to 30 “heads” journey through Sudan’s northern desert to the Libyan border, where they are delivered to another group of smugglers.

“If you die in the desert, no one would know,” said Mr. Ibrahim, the smuggler, elaborating on the dangers of the trip.

In Libya, the migrants stay in smuggler camps. Those who have not fully paid are told to call their family for the balance. Sometimes, extra payments are extracted to release migrants who are effectively held hostage.

“There are children that run away, make their arrangements with smugglers, call their parents, ‘Mom, I’m in Benghazi’” Bernardo said.

The Sudanese government is paying more attention to migration. Last year, the Sudanese Parliament passed an extensive anti-human-trafficking bill and held an international conference to address the problem.

“We lack the experience and are calling for more training,” said Awad Dahia, head of passports, immigration and civil registration at the Ministry of Interior.

But some migrants contend that Sudanese officers are involved in the illegal trade as well.

“If there is credible evidence against anyone, an officer or a government official, then the law should be applied against them,” Mr. Dahia said.

For the migrants and refugees here who want a better life and to move on, there is a debate on the fruitfulness of the risks taken.

Mr. Abraham, who said that he was worried that his 14-year-old son would also try to leave, believes that the risks taken by the younger generation of refugees and migrants are not worth it.

“They are after a life that does not exist,” he said.

But Mr. Taero, the former university student, felt that was no reason to stay.

“It does not matter,” he said. “I am also dying here.”