Four women who drove into a forbidding desert and left food and water for migrants crossing illegally into the United States were following their religious beliefs, not violating federal laws, a federal judge has ruled, reversing their criminal convictions.

Judge Rosemary Márquez of the United District Court in Arizona decided last week in favor of the women, members of the organization No More Deaths, a faith-based group in Tucson that aims to alleviate suffering at the border.

“The depth, importance and centrality of these beliefs caused defendants to restructure their lives to engage in this volunteer work,” Judge Márquez said in a 22-page ruling that was released on Monday.

She also appeared to rebuke federal prosecutors for trying to argue that leaving behind food and jugs of water in the desert would have the effect of encouraging more migrants to cross the border.