A French farmer, who has become a local hero for helping African migrants cross the border from Italy and giving them shelter, has gone on trial for aiding illegal arrivals.

Cédric Herrou is one of three people to appear before courts in southern France for assisting people fleeing to Europe.

The 37-year-old activist, accused of “helping undocumented foreigners enter, move about and reside” in France, faces up to five years in prison and a €30,000 (£25,500) fine if convicted.

Herrou’s olive farm sits in a valley on the border of Italy, near a popular route for migrants trying to slip past border controls.

He has been unapologetic about helping people travelling through Europe via the often perilous boat journey across the Mediterranean.

“If we have to break the law to help people, let’s do it!” he told supporters outside the Nice court on Wednesday, where a crowd of about 300 people gathered.

“Our role is to help people overcome danger, and the danger is this border,” he said, accusing French police of detaining “thousands” of minors and dumping them back across the border.

In October, Herrou led a group of activists who occupied a disused holiday village belonging to the SNCF state railway company and opened it up to a group of migrants.

Police intervened after three days to evacuate the makeshift camp and arrested Herrou.

Two months earlier, he was arrested for trying to smuggle eight Eritrean migrants by car from Italy into France. That case was later dropped, with prosecutors accepting that he acted on humanitarian grounds.

However, he is now accused of being more activist than good samaritan.

Herrou is part of a network of citizens and activists who have resorted to semi-clandestine tactics in assisting migrants who are regularly removed by the police from trains crossing into France and sent back to Italy.

Outlaws for some, they have been likened by others to the French people who helped hide Jews during the second world war.

A university researcher was also prosecuted in October after being caught giving a lift to three Eritrean women near Nice, shortly after their arrival from Italy.

The ruling in the researcher’s case is expected on Friday. Prosecutors have called for a six-month suspended sentence.

In December, a 73-year-old academic was fined €1,500 for a similar infringement.