Hungary has closed its border with Croatia in an effort to stem the flow of migrants through the country en route to western Europe.
Croatia said it would begin directing migrants to Slovenia instead.
Hungary has been a major transit country for migrants, many of whom aim to continue on to Austria and Germany.
It announced the closure on Friday after EU leaders failed to agree a plan backed by Hungary to send a force to prevent migrants reaching Greece.
The border, reinforced with a razor-wire fence, closed at midnight (22:00 GMT) on Friday.
A group of several hundred migrants who arrived near the village of Zakany minutes before the deadline were the last to be allowed through.
"Closure!" a soldier shouted after the last travellers had passed across.
"We know that this is not the best, but only the second-best solution," Hungarian Foreign Minister Peter Szijjarto said, announcing the closure earlier. Migrants could still apply for asylum in Hungary at two border transit zones, he added.
The border posts at Beremend and Letenje are also open for anyone with valid documents.
Hungary has already sealed its border with Serbia.
There are fears in Slovenia that closure of the Croatia-Hungary border will channel many more migrants through Slovenia.
Ranko Ostojic, Croatia's interior minister, said Croatia was "turning the route, the corridor, towards Slovenia".
Croatia has not struck any agreement with Slovenia, according to Mr Ostojic. "This is (purely) a Croatian plan," he said.
In response, Slovenia stopped all passenger rail transport from Croatia, the country's national railway company announced.
Slovenia's Interior Minister, Vesna Gjorkos Znidar, said extra police had been deployed to the border with Croatia.
But she said the country will keep accepting refugees as long as neighbouring Austria and Germany keep their borders open.
Earlier on Friday, Turkish officials stressed that a plan agreed by EU officials for joint action with Turkey on the migrant crisis had not been finalised.
EU leaders have agreed to speed up visa liberalisation talks for Turks if Turkey stems the influx, as well as to "re-energise" talks on Turkey joining the EU and supply more aid.
German Chancellor Angela Merkel said EU states were considering a Turkish request for €3bn (£2.2bn, $3.4bn) in aid.
But Turkish President Recep Tayyip Erdogan has heavily criticised Europe's reaction to the migrant crisis.
"They announce they'll take in 30,000 to 40,000 refugees and then they are nominated for the Nobel for that. We are hosting two-and-a-half million refugees but nobody cares," he said.
Nearly 600,000 migrants have reached the EU by sea so far this year, many of them travelling from Turkey.
Migrants arriving in Europe
migrants have arrived by sea in 2015, says IOM
migrants have died trying to cross the Mediterranean
76% arrived in Greece via the eastern route
70.1% of arrivals in Greece were from Syria
10,043 migrants arriving in Italy were unaccompanied children
710,000 migrants have crossed EU borders this year, according to Frontex figures
Source: IOM, Frontex
Ms Merkel is due to travel to Turkey at the weekend. "There is still a huge amount to do," she said, "but you cannot say that we've achieved nothing."
EU sources had said several countries were cautious about coming to an agreement with Turkey too quickly, including Greece, Cyprus and France.