Baton-wielding Hungarian riot police unleashed tear gas and water cannons against hundreds of refugees after they tried to surge into the country from Serbia.
Crying children fled the acrid smoke and dozens of people were injured in the chaos.
With their path blocked, hundreds of other asylum-seekers turned to a longer, more arduous path to Western Europe through Croatia, where officials said 1,300 had arrived in a single day.
On the sealed border into Hungary, frustrated men - many of them war refugees from Syria and Iraq - hurled rocks and plastic water bottles at the helmeted riot police as they chanted "Open" Open!" in English.
Children and women cried as the young men, their faces wrapped in scarves, charged toward the police through thick smoke from tear gas and tyres set on fire by the crowd.
"We fled wars and violence and did not expect such brutality and inhumane treatment in Europe," shouted an Iraqi, Amir Hassan, his eyes red from tear gas and his hair and clothing soaked after being hit by blasts of water cannon spray.
"Shame on you, Hungarians," he shouted pointing in the direction of the shielded policemen who were firing volleys of tear gas canisters directly into the crowd.
Around him, women screamed and wailed, covering their faces with scarves as they poured bottled water into their sobbing children's eyes to relieve the stinging.
Children gasped from the gas, and blood streamed down the face of one man as he ran from the melee, carrying a youngster.
People fainted from the noxious plumes of tear gas, including one woman who collapsed while holding a baby.
At least two people were seriously injured and 200 to 300 others received medical care for tear gas inhalation and injuries such as cuts, bruises and burns, said Dr Margit Pajor, who treated people at a medical centre in Kanjiza, Serbia.
UN Secretary-General Ban Ki-moon expressed "shock" at the behaviour of Hungarian police, calling it unacceptable.
Referring to Syria, he said: "People facing barrel bombs and brutality in their country will continue to seek life in another."
Hungarian authorities insisted they acted legitimately in self-defence, describing the refugees as violent and dangerous.
"We will employ all legal means to protect Hungary's border's security," said Gyorgy Bakondi, homeland security adviser to Prime Minister Viktor Orban.
"We will not permit violent, armed, aggressive attackers to enter."
The ugly developments in Europe's migrant crisis took place after some of those massed in Serbia broke through a gate.
They and hundreds of others had grown desperate after Hungary sealed off its border with Serbia with a razor-wire fence the day before to stop the huge numbers of migrants entering Hungary, which lies on a popular route to Western Europe.
More than 200,000 have entered Hungary this year alone, turning the country into one of the main entry points into Europe for the rising numbers of people fleeing war and persecution in Syria, Iraq and elsewhere.
Mr Orban said he plans also to build stretches of fence along the border with Croatia.
His government has said it was also extending the fence along a stretch of its border with Romania.
Both Croatia and Romania, like Hungary, are members of the EU, and the moves are straining ties with those allies and herald the unusual prospect of fortress-like barriers between EU states.
It was clear that Hungary's ties with Serbia were facing deep strains.
Hungary's foreign minister, Peter Szijjarto, decried what he called "brutal attacks" by the refugees against Hungarian police and asked Serbian authorities to crack down on the asylum seekers on its soil.
Serbia said it would send more police to the border to separate the refugees from Hungarian police.
But Prime Minister Aleksandar Vucic condemned the "brutal treatment" of migrants by Hungarian police.
"We will not allow anyone to humiliate us and we will not allow anyone to throw tear gas on Serbia's territory," he said.
Hungarian authorities said they have arrested 519 migrants who tried to cross the border since tough new laws went into effect on Tuesday making it a crime to cross from Serbia anywhere other than at legal checkpoints.
They launched 46 criminal prosecutions and found nine people guilty, the first convictions based on the new laws.
The asylum-seekers, who were escorted into court in handcuffs, were expelled from Hungary and banned from re-entering the country for either one or two years.
Syrian president Bashar Assad blamed Europe for the crisis, saying it was a direct result of the West's support for extremists in Syria over the past four years.
In an interview with Russian media, he accused Europe of supporting "terrorism" and providing "protection for terrorists, calling them moderates".
Elsewhere in Europe, migrants remained on the move.
Greek police said some 5,000 people trying to reach Western Europe crossed the country's northern border with Macedonia over the 24-hour period from Tuesday morning to Wednesday morning.