BIHAC, Bosnia and Herzegovina — His right arm was swollen and badly bruised. He didn’t so much walk as shuffle because of injuries to his legs that, like those elsewhere on his body, he said were inflicted by Croatian police batons.

Grimacing from pain and exhaustion as he staggered back into Bosnia last month after yet another fruitless effort to sneak across the border into Croatia and enter the European Union, Aman Mutani, a 23-year-old from India, muttered the words that European leaders these days long to hear.

“There is no hope,” he said, tears of despair and shame welling in his eyes. “I am going home.”

With anti-immigrant populists on the rise across Europe, and even the German chancellor, Angela Merkel, in retreat from her open-door refugee policy, Europe’s long struggle to reconcile political reality with human sympathy for desperate people has come to an end in the forested hills along northwestern Bosnia’s border with Croatia.

Croatia denied reports by rights groups and aid workers of brutality.

Mr. Mutani and thousands of others mostly came to Bosnia from Serbia, which offers visa-free entry to Indians and, until recently, Iranians. Serbia had been the main jumping-off point to the European Union for migrants and refugees traveling the so-called Balkan Route through Greece and the former Yugoslavia.