HAMILO, Greece — Defying Europe’s border closures, more than 2,000 migrants and refugees stranded in Greece braved torrential rain and waded across a fast-flowing river Monday to walk into Macedonia.

But their time in Macedonia and planned journey onward toward Western Europe might be short-lived. Macedonian soldiers and police detained hundreds of people after they had just crossed from Greece and put them into trucks, authorities said.

The events were the biggest challenge to border closures since the route from Greece to central Europe was sealed off 10 days ago, leaving more than 40,000 people stranded in Greece. It came days before European Union leaders try to hammer out a deal with Turkey to try to hold more refugees there.

The migrants walked out of the crowded camp of Idomeni on the border, traveling west on foot.

“The border restrictions imposed by the countries have forced people to take desperate actions,” said Ljubinka Brasnarska, a U.N. refugee agency spokeswoman.