Afghan resident and former refugee Ghafour Aryan, 24, shown here in Kabul, risked death on the migrant trail and two months in “nightmarish” refugee centers in Germany, before being sent back to Afghanistan. (Wakil Kohsar/AFP/Getty Images)

When Ahmad Ghyasi fled Afghanistan for Germany last fall, he left with a stack of papers he was sure would help his case for asylum.

He had evidence he was a Taliban target and references from the U.S. military. But German authorities made it clear, Ghyasi said, that it was unlikely they would ever grant him asylum. And now Ghyasi, a longtime interpreter for U.S. forces, is back in Afghanistan after just three months abroad.

Today, German and Afghan officials are negotiating an agreement that could see thousands of Afghans return to the country on either chartered or commercial flights from across Europe over the next few months. Germany wants to begin sending Afghans back immediately, officials here say. The Afghan government has insisted Germany provide Afghanistan with more economic aid to absorb the influx.

Germany announced a blanket ban on Afghan asylum seekers in December, on the grounds that they are fleeing poverty not war. The move came as Europe grappled with last year’s record flow of migrants, and one of the world’s worst humanitarian crises in years.

But Germany’s decision to block Afghan refugees — and urge others to go home — has highlighted the international community’s failure to stabilize Afghanistan and locked the German and Afghan governments in a dispute over who is responsible for the thousands of migrants who may be forced to return.

Close to 180,000 Afghans applied for asylum in Europe in 2015, E.U. figures show. Only about 1,000 Afghans in Germany have said they are willing to go back to Afghanistan. Last year, more civilians were killed or injured in Afghanistan than in any period since 2009, the United Nations says. The rise in violence even prompted Germany to keep its troops in Afghanistan indefinitely.

“NATO failed in Afghanistan, but they don’t want to say this. They spent billions [of dollars] here and still there is no security,” Ghyasi, 28, said in an interview at the Kabul safe house where he now lives.

NATO and its partner nations, including Germany and the United States, maintain roughly 12,000 troops in Afghanistan to train and assist local security forces in their fight against the Taliban. Still, violence here has been on the rise.

The Taliban ruled Afghanistan from 1996 to 2001 but now control more territory than at any time since the invasion that toppled their regime more than a decade ago, U.S. officials say. In October, the insurgents briefly seized the northern city of Kunduz, a once-peaceful city that hosted more than 1,000 German troops.

“If there was security, why would we leave Afghanistan?” said Ghyasi, who, as a translator for U.S. forces, applied for a Special Immigrant Visa to the United States.

The visas are granted to some Afghans who worked with U.S. and other international forces. Ghyasi says German authorities asked him why he did not flee to the United States.

The answer, he says, is that getting an American visa is a difficult and drawn-out process, and that without one it is impossible to cross the Atlantic. Germany, on the other hand, is reachable over land.

“Who would willingly leave their homes and families like this?” he said. “The biggest mistake I made was working for the U.S. Army. It has cost me a lot. Everything I have.”

According to the E.U.’s statistics body, Eurostat, Afghans are now the second-largest group of migrants in Europe after Syrians. But about half of fleeing Afghans will have their asylum claims rejected by German authorities, migration experts say.

Afghans have also applied for asylum in large numbers in Sweden, Hungary and Austria.

Last year, Germany’s interior minister called the tide of migrants from Afghanistan “unacceptable” and reprimanded Afghans for fleeing while hundreds of German troops are still in the country.

German Chancellor Angela Merkel suggested the displaced leave volatile areas for more secure cities inside Afghanistan, where Germany would assist with development aid.

But even in the capital, Kabul, insurgents are launching an increasing number of deadly attacks, causing an 18 percent increase in civilian casualties in the city in 2015, according to the United Nations.

“There are some cities that are secure, but there is fighting in many more places,” said Ghafour Aryan, a 24-year-old student who left for Germany last summer but returned to Afghanistan in February.

Aryan says he spent about nine months at a string of hostels and migrant camps in Germany before flying home with another 120 Afghans on a special flight chartered by the German government for returnees in February.

German authorities never asked Aryan to explain why he left, he said, and claimed Afghans were barred from taking German-language courses provided to Syrians and Iraqis in the camps.

“Germany’s stance is this: They want to expel by force the Afghan refugees whose cases have been rejected,” said Islamuddin Jurat, spokesman for Afghanistan’s Ministry of Refugees and Repatriation. “But the Afghan government won’t accept this.”

The German Embassy in Kabul did not respond to a request for comment.

If mass numbers of migrants are sent back to Afghanistan, the government wants Germany “to help invest in the economy, to create jobs and to help the communities” to which the refugees are returning, Jurat said. “Afghanistan can’t stop the migration on its own.”

Afghanistan is pushing for at least four categories of asylum seekers to be allowed to stay in Germany, even if their applications have been rejected, officials close to the negotiations say. The categories are minors, female-headed households, disabled people and residents of areas where insurgents are fighting the government.

“The Afghan government wants to exploit the opportunity and negotiate with Germany to help them invest in economic areas — to create jobs for communities,” said an official with the International Organization of Migration, an intergovernmental organization that advises governments on displacement. The official spoke on the condition of anonymity because the details of the negotiations between Germany and Afghanistan have not yet been made public.

The push by Germany and other E.U. countries to depict Afghan migration as an economic problem is part of a “broader desire among European policymakers to put Afghanistan behind them,” the European Council on Foreign Relations wrote in a recent brief. But Afghanistan, the brief concluded, is “far from truly secure.”