WARSAW — Hungary closed its border with Croatia early Saturday to stem the flow of thousands of migrants who had been making their way into the heart of Europe — just over a day after European Union leaders failed to reach a deal to seal the bloc’s outer borders.

The Hungarian foreign minister, Peter Szijjarto, told reporters in Budapest on Friday that his country was taking the action for two reasons: it had finally completed a razor-wire fence along the 216-mile border and, more crucially, because the European Union had yet to come up with a comprehensive plan to deal with the flow of migrants.

For the last month, a migrant trail has operated freely, with countries along the route from the Balkans to Germany allowing those seeking asylum to pass through their territories — as long as they either applied for asylum or exited on the other end.

The arrangement has helped to avert the kind of humanitarian crises that erupted in Central Europe in late August and early September, when migrants fleeing war and poverty in the Middle East, Africa and elsewhere began pouring into the Balkans in huge numbers.