Where to? “Germany!” several of his travel companions shouted. “Austria,” one man said. “I will go to Sweden,” Mr. Atti said.

But after a month of harrowing travel, rushing to reach Central and Northern Europe before more borders are closed, the Afghan migrants may be facing a new obstacle to their dreams of safety and security: a hardening stance by the German government on who gets to stay for a year, or more.

German officials argue that Afghanistan is not universally unsafe, so not all migrants should be granted asylum. The interior minister, Thomas de Maizière, has said that applicants will be judged case by case, adding that “not all of the people who come to us as refugees from Afghanistan can expect to stay in Germany.”

Officials in Germany also note that the country has had troops in Afghanistan for 14 years and has poured more than 2 billion euros, or about $2.15 billion, into civilian projects. Chancellor Angela Merkel has suggested that those efforts fulfill Germany’s commitment to care for those in need, meaning it should not necessarily have to shelter Afghans in Germany, too.

That tougher stance by Germany is emerging as the biggest test case yet of Central and Northern Europe’s willingness to absorb people from the world’s most troubled regions. At the same time, it may force a debate over who qualifies as a refugee.