Hungarian riot police have fired tear gas and water cannon to force migrants back from the Serbia-Hungary border.
Hundreds of people have massed at a closed crossing point near the Serbian town of Horgos, and are involved in a tense stand-off with police on the other side of the border.
Some migrants threw missiles, including stones and water bottles.
Many of the migrants want to reach Germany, amid divisions within the EU over how to deal with the crisis.
Tens of thousands of people have crossed into Hungary to enter the Europe Union’s Schengen zone, which normally allows people to travel between member countries without restrictions.
Hungary closed its entire border with Serbia on Tuesday after making it illegal to enter the country or damage a new razor-wire border fence. The country’s courts have started fast-track trials of arrested migrants.
Serbia’s foreign ministry has protested over the firing of tear gas and water cannon into its territory.
There were chaotic scenes near Horgos, with fires burning and police vehicles and ambulances arriving on the Serbian side of the border, across from massed ranks of riot police on the Hungarian side.
The Hungarian government says 20 police officers were injured as migrants tried to break through a gate, and a spokesman accused migrants of using children as “human shields”.
The firing of tear gas and water cannon created a stampede of migrants away from the border.
Several people received treatment from the Serbian ambulance service, some suffering the effects of tear gas.
Migrant Amir Hassan, from Iraq, said: “We fled wars and violence and did not expect such brutality and inhumane treatment in Europe.”
United Nations Secretary General Ban Ki-moon said he was “shocked” by the “unacceptable” treatment of migrants.
At the scene: James Reynolds, BBC News, Serbia-Hungary border
A clash was inevitable. For more than an hour, in the afternoon heat, a group of migrants and refugees stood inches from a line of Hungarian riot police at the border gate. A water cannon stood behind the police.
“Open the gate, open the gate,” the group shouted.
They hoped their presence might somehow persuade Hungary to reopen its border. But the Hungarian police did not move. Several people began to throw empty water bottles towards the Hungarian line.
Minutes later, riot police fired tear gas canisters in unison. The crowd ran backwards, nearly knocking over tents.
I ran back with the crowd, with the sting of tear gas in my eyes. Several refugees pointed me towards a father carrying a baby – both had been caught up in the tear gas.
Away from the crowd, the atmosphere was calmer. Families sat on the ground next to their tents. From the back, we watched the Hungarian police fire water cannon – the water flared a rainbow colour in the sun.
We also watched young men continue to throw objects towards the Hungarian police lines.
Hungarian Foreign Minister Peter Szijjarto said he considered it “unacceptable that an aggressive group of immigrants took such an action against Hungarian police. The Hungarian police’s duty is to protect Hungary from the entry of such violent persons.”
Serbian minister Aleksandar Vulin, visiting the scene, said the migrants’ frustration was understandable after Hungary closed the border.
“Hungary must show it is ready and capable to accept these people,” he said.
Serbia has said it will send additional police to its border with Hungary.
“The aim is to prevent further attacks on the Hungarian police from our territory and in a humane and respectful way distance the migrants from the fence and the Hungarian police,” said Interior Minister Nebojsa Stefanovic in a statement.
The UN High Commissioner for Refugees, Antonio Guterres, called on the Hungarian authorities to ensure “unimpeded access” for people fleeing wars and persecution.
“UNHCR was especially shocked and saddened to witness Syrian refugees, including families with children who have already suffered so much, being prevented from entering the EU with water cannon and tear gas,” a statement said.
Meanwhile, Croatia has said it will allow migrants to travel on to northern Europe, opening up a new route a day after Hungary sealed its border with Serbia.
A steady stream of migrants is crossing into Croatia from Serbia, with some of those stranded on Serbia’s border with Hungary now using the same route.
Croatian Prime Minister Zoran Milanovic said: “We are ready to accept and direct those people… to where they apparently wish to go.”
Source: BBC News