Hungary had moved swiftly to show that it would enforce its new laws. On Wednesday, the government announced that police officers had detained 519 people for illegal entry or damaging a border fence since the new rules came into force a day earlier. The authorities have opened 46 criminal cases, and the first suspects were to appear in court Wednesday afternoon, according to Mr. Bakondi, the prime minister’s aide.

Court officials in Szeged, Hungary, said that nine adults — seven from Iraq, two from Syria — would be deported for illegally crossing, after expedited court proceedings.

The ripple effects of Hungary’s crackdown reached as far as Istanbul, where hundreds of migrants were huddled in informal camps after they were prevented from leaving Turkey or picked up on highways and brought back to the city. Still, some had made it to Edirne, on the European side of Turkey, where migrants thronged a bus station in the hope of getting clearance to walk to the border with Greece, and some threatened a hunger strike until they were let through.

“We’ll go to Greece, then Serbia, but skip Hungary and go through Slovenia, instead,” said one Syrian migrant, Ghassen Tekriti, who arrived in Edirne on Tuesday.

At the Macedonian border and in towns like Kanjiza, Serbia, where migrants had pooled in recent months before making the trek across the Hungarian border, buses appeared Wednesday, offering to take people directly to the Croatian border.

“Our friends told us not to go to Hungary, because they would put you in prison for three years if you tried to cross the border,” said Daban Sabir, 25, a student from Suleymani, Iraq, who was one of the first migrants to test the new route into the European Union through Croatia and Slovenia.

Clutching a document from the Serbian authorities that he had been told was essential to enter Croatia, Mr. Sabir and the others moved down the road toward a line of Croatian police vans sitting between radish and corn fields.

“I believe this is a trend which will increase in coming days,” said Terence Pike, who works with the United Nations High Commissioner for Refugees in Croatia.