Refugees blazed a new pathway through Europe on Wednesday, with hundreds hiking through cornfields to reach welcoming Croatia even as others faced tear gas and water cannons from Hungarian police determined to turn them away.

The contrasting scenes along the Serbian border highlighted both the make-or-break resolve of the asylum seekers and the growing friction facing Europe, which has failed to create a coordinated policy for the unprecedented influx of economic migrants and war refugees from the Middle East, Africa, Afghanistan and Pakistan.

“We hit a stone and we flow around it,” said Arazak Dubal, 28, a computer programmer from Damascus, who had been on the road for 18 days.

He and his three companions reached Belgrade only to discover on Facebook and WhatsApp that the Hungarian border was closed to refugees.

“So I went to Google Maps, and here we are,” said Dubal, huffing in the hot afternoon as he trudged across the farm fields.

A two-hour drive to the northeast — along Serbia’s frontier with Hungary — the route was slammed shut.

Just steps from Hungary, thousands of people spent the night in the wet grass on the Serbian side of the border. Hours later, hundreds tried to punch through the cordon of razor wire and riot police massed near the Serbian border town of Horgos.

But they ran headlong into security forces­ who unleashed tear gas and pepper spray to drive them back. Some refugees were swatted by batons and crumpled to the ground in pain.

“Open the door!” the refugees yelled as they hurled water bottles and debris at riot police.

Nearby, children screamed for their missing parents. Water cannons sprayed crowds on the Serbian side, forcing refugees to retreat to a squalid squatters’ camp that took root just after Hungary closed the border Tuesday.

There were no major injuries, but some refugees were treated by Serbian authorities for respiratory problems from the tear gas and at least one migrant had a leg injury, the Associated Press reported.

It was the first major clash between security forces­ and migrants since police used stun grenades to stop refugees from crossing into Macedonia from Greece almost a month ago.

“We fled wars and violence and did not expect such brutality and inhumane treatment in Europe,” said Amir Hassan, who was drenched from a water cannon and tried to wash tear gas from his eyes, according to AP.

“Shame on you Hungarians!” he shouted, pointing toward the Hungarian police.

At the United Nations, Secretary General Ban Ki-moon called Hungary’s border crackdowns “unacceptable.”

“All the countries have their domestic problems,” he said, “but since they are the people fleeing the wars and persecutions, then we must show our compassionate leadership.”

Neighboring countries continued to heap scorn on Hungary’s decision to blocks its southern border.

“Barbed wire in Europe in the 21st century is not an answer, it’s a threat,” complained Croatia’s prime minister, Zoran Milanovic, in a direct jab at the blockades by neighboring Hungary.

Milanovic promised that refugees would be allowed to pass through his country.

He told lawmakers in Zagreb that Croatia would “accept and direct” the migrants to transit the country — comments that rocketed through the social media networks used by the refugees and increased the march toward Croatia.

The river of migrants was swelling by the hour.

By late afternoon, more than 600 migrants walked through fields and along small roads to cross from Serbia into Croatia, a European Union member, where officials set up posts to register names and details.

Many traveled by bus from Macedonia and Hungary; others pulled up in taxis before crossing the border on foot and receiving a polite reception from authorities.

“We want to keep them moving as quickly as possible,” said Zdravko Helic, a civil protection officer in Tovarnik.

He was proud to add, “We haven’t had a single incident.”

Saeed, 19, a student from Damascus, called Hungary’s treatment of the refugees “old-fashioned racism.”

“We’re the first today,” said Dubal, the Syrian refugee. “There’ll be thousands tomorrow.”

Afterward they were taken by bus to a refugee processing camp outside the capital, Zagreb, where they would be officially registered.

What happens after Zagreb was uncertain.

Croatian officials said they would probably allow the migrants to continue their journeys by bus and train to Slovenia, Austria, Germany and beyond. But it was only Croatia’s first day at the leading edge of the mass migration, and authorities were scrambling to coordinate their response with E.U. partners.

“We will walk all the way to Germany if we have to,” said Mohammad, 28, who worked in a mobile phone store in Aleppo, Syria’s largest city.

“Shop is gone, house is gone, some of family is gone,” he said. “So I will walk.”

Like many in the migrant stream, he declined to give his last name out of fear of reprisals against relatives back home.

The refugees had nothing good to say about Hungary. “Not nice at all,” said Abdullah, 24, from Aleppo, who smiled and waved at the Croatian police before they hustled him into a van.

“See? Very good service,” he joked.

Souad Mekhennet in Vienna, Gergo Saling and Jodi Hilton in Horgos, Serbia, and Brian Murphy in Washington contributed to this report.

Read more:

Germany’s enthusiasm for refugees might not last. These maps explain why.

Refugees get a chance to wash and rest their weary soles in Budapest

Read The Post’s coverage on the global surge in migration