TISZASZIGET, Hungary — Roiling everything in its path, a wave of tens of thousands of migrants and refugees — many fleeing wars in Iraq, Syria and Afghanistan — has worked its way up the length of the Balkans in recent days.

Like a movable feast of despair, the mass of people has overwhelmed the authorities in one stop after another, from the tiny Greek island of Kos to impoverished Macedonia, which declared a state of emergency last week, and now the train and bus stations of Serbia, as they head north to their ultimate destinations in the richer nations of the European Union.

The next link on their route, almost inevitably, are towns like this one on the Hungarian frontier with Serbia. But Hungarian officials say they have a firm, if unwelcoming, answer to the slow-motion tide: a fence.

Still under construction, parts of it are already laced across fields and river banks or trace old railway tracks, and it will be as tall as 13 feet in some places, a patchwork intended to send a clear message that the migrants should not expect to move freely.