Get breaking news alerts and special reports. The news and stories that matter, delivered weekday mornings.

ROSZKE, Hungary — Crowds of frustrated migrants demonstrated on the Serbian side of the Hungarian border on Tuesday, chanting and displaying signs reading "Europe, Shame."

Hungary shut its borders to migrants from war-torn Syria and beyond earlier in the day, telling those who wanted to cross that they would have to travel to a transit center and apply for asylum.

Police made the announcement through an Arabic translator just after midnight at Horgos II border crossing on the border with Serbia, where hours earlier a few migrants at a time had been allowed through a small gate. Many had walked a mile from a popular railroad crossing near the village of Roszke after it, too, was locked down by riot police.

Horgos II had been one of the only remaining crossing for migrants in a newly constructed border fence by which Hungary hopes to stem the flood of people. Police were under instructions to detain those trying to cross the border illegally, a criminal offense now punishable by prison or deportation.

"We will start a new era," government spokesman Zoltan Kovacs said shortly after midnight at the border. "We will stop the inflow of illegal migrants over our green borders."

Within hours, the government said it was declaring a crisis in two southern counties because of the influx of migrants traveling from Serbia.

Let our news meet your inbox. The news and stories that matters, delivered weekday mornings. This site is protected by recaptcha

On Monday, Hungarian Prime Minister Viktor Orban invoked his country’s right to defend “our culture, our way of life and our sovereignty.”

"Hungary is a country with a 1,000-year-old Christian culture. We Hungarians don't want the global-sized movement of people to change Hungary,” Orban said in remarks to police bound for the border.

Serbia is not in the European Union — but Hungary is, which is why thousands of migrants and refugees have used it as a path to the more prosperous countries of northern and western Europe. Many more are still on their way, moving through the Balkans by train, bus and taxi in an attempt to beat the border crackdown.

More than 190,000 migrants and refugees fleeing poverty and war in the Middle East, Africa and Asia have been recorded entering Hungary from Serbia this year, many of them having crossed the water from Turkey to Greece, police say.

Hungary appeared to be sending the current wave of migrants onto trains directly to the Austrian border, a Reuters photographer reported late Monday.

Austria followed Germany in re-imposing Europe's internal border controls, effectively suspending a two-decade old policy allowing border-free travel across the continent.

The 28 countries of the European Union are debating how to handle the crisis: how many migrants and refugees to accept, and how to help them resettle.

Morgan Johansson, Sweden’s justice and migration minister, said he hoped the EU could agree on a plan to “redistribute” 120,000 refugees who’ve ended up in Italy, Greece and Hungary, “because we really need to share this responsibility, with solidarity, with other countries."

A Syrian migrant sits on the tracks at the Serbian border with Hungary as she and her family wait for darkness before heading across country in Hungary on Sunday. Christopher Furlong / Getty Images

Earlier, just before Hungarian police closed the railroad crossing, a Syrian family ran down the tracks trying to make it through, the patriarch screaming to his wife and small children, "Yallah, yallah!" — Arabic for "Let's go!"

They made it through.

So did Mohammed Al-Hamdan, 17, also from Syria.

He said that he had not slept for three days hoping to make it through, and just a day earlier he had been in Greece, racing to make it through Serbia and Macedonia.

"We have to hurry up," Al-Hamdan told NBC News as he walked down the tracks. "They're going to close the border soon."

But he did not smile when he made it over the border.

"I'm not happy," he said. "I had to leave Syria — I love Syria, but so much killing there."