A Hungarian security officer fired three warning shots early on Tuesday after around 60 migrants tried to force their way through a checkpoint on the border with Serbia.
Serbian police said later they had arrested 37 people for trying to cross the frontier illegally.
No one was wounded in the incident, which took place at the Roszke/Horgos border crossing, Hungarian police spokeswoman Szilvia Szabo said.
Hungarian police said the group tried to enter the European Union member state at the crossing at about 5.30am local time, prompting the security officer on site to fire the warning shots.
There are thousands of migrants stuck in Serbia, with more than 6,000 people living in government-operated camps.
On Tuesday, in the village of Horgos, on the Serbian side of the border crossing, a group of about two dozen migrants from Iraq, Syria, Afghanistan and Morocco said they were beaten up by Hungarian police and sent back to Serbia.
"My friends they have tried to cross the border and the police of Hungary, they reacted badly about that, they were hitting them, they broke their phones," Mohab, a migrant from Morocco, who acted as an interpreter for the group, told Reuters.
"They shoot bullets in the air and people run," he said.
The crossing was the scene of a large-scale riot at the peak of Europe's migrant crisis in 2015, when police clashed with hundreds trying to break through the frontier into the EU.
Hungarian Prime Minister Viktor Orban subsequently ordered a steel fence erected along Hungary's border, curbing arrivals.
But migrant traffic started increasing again late last year.
Gyorgy Bakondi, an adviser to Mr Orban, cited police statistics which he said showed a sharp rise in attempts to cross Hungary's southern borders.
There had been 3,400 attempts made so far this month, compared to just several hundred a month last year, he said.
Most of Tuesday's group failed to cross the border, and the four who managed to enter Hungary were intercepted, police said, adding that the crossing had been closed.
A larger highway checkpoint for international passenger and freight traffic remained open, police said.
Earlier this month, Hungarian police said it had sent reinforcements to the border and launched a boat patrol on the river Tisza, which forms part of its frontier with Serbia.
Hungary’s prime minister says he is defending a border of the EU's passport-free Schengen zone. But he has been criticised by Brussels and rights groups for his tough border security policy.