Hungary is to close its border with Croatia, where it has built a razor-wire fence, in order to stop the free flow of migrants.
Following a meeting of the national security cabinet, foreign minister Peter Szijjarto said that "the Hungarian-Croatian green border will be closed from midnight".
Hungary clamped down on its border with Serbia with a similar barrier on September 15. Since then, migrants have been taking a detour through Croatia to reach Hungary.
More than 383,000 migrants have entered Hungary this year, nearly all passing through on their way to Germany and other destinations further west in the EU.
Mr Szijjarto said that normal border checkpoints between the two countries will remain open, though inspections will be tightened.
"We will introduce stricter controls to be able to block border crossings done illegally," he said.
Although Croatia is also a member of the European Union, unlike Hungary it is not part of the Schengen zone of passport-free travel. Migrants could still apply for asylum in Hungary at two border transit zones, Mr Szijjarto said.
After midnight, many of the migrants already in Croatia are expected to try to head towards Slovenia, another EU country in the Schengen zone, which also shares borders with Hungary and Austria. However, experts fear that many will get stuck in Croatia, which is ill-prepared to provide for them in large numbers.
"There is no way Croatia can cope with ... accommodating and providing for the immediate needs for these people," said Lydia Gall, a researcher for Human Rights Watch in Budapest. "Within days you would end up having tens of thousands of people in Croatia and further down the Western Balkan route, in Serbia and Macedonia."
Hungary decided to order the border clampdown after EU leaders meeting in Brussels on Thursday failed to agree on a plan backed by Hungary to send EU forces to block migrants from reaching Greece.
"We know that this is not the best, but only the second-best solution," Mr Szijjarto said about closing the Croatian border.
Hungary's fellow members of the so-called Visegrad Group - Poland, the Czech Republic and Slovakia - are sending dozens of soldiers, police and equipment to support Hungarian forces guarding the border with Croatia.
Hungarian officials said this co-operation would be an example to the rest of the EU regarding joint border protection.