NEW YORK (CBSNewYork/AP) —  A federal judge on Tuesday ordered the immediate release of an Ecuadorean immigrant detained while delivering pizza to an Army base in Brooklyn.

“Although he stayed in the United States unlawfully and is currently subject to a final order of removal, he has otherwise been a model citizen,” U.S. District Judge Paul Crotty wrote of Pablo Villavicencio.

The Manhattan judge said Villavicencio, who was being held at a New Jersey lockup, can remain in the United States while he exhausts his right to try to gain legal status. Villavicencio applied to stay in the U.S. after he married a U.S. citizen, with whom he has two young girls. The overjoyed father was reunited with all three of them Tuesday night, after being detained for nearly two months.

“Thank you for everything, thank you for everything you guys, the press,” Villavicencio said.

The judge cited those children as part of his decision, and said they are U.S. citizens.

“He has no criminal history,” the judge wrote. “He has paid his taxes. And he has worked diligently to provide for his family.”

The U.S. government, which had wanted the case moved from New York to New Jersey, did not immediately comment on the judge’s action.

Attorney Gregory Copeland, representing Villavicencio, said his lawyers expected him to be released Tuesday night. Villavicencio’s wife said she was home in Hempstead waiting for a car to take her to the detention center, where she would meet with him and lawyers.

Adriene Holder, the attorney-in-charge of the civil practice at the Legal Aid Society, said the rule of “law, humanity and morality” prevailed and the Villavicencio family has “finally received a crucial measure of relief from their 53-day nightmare.”

“This decision should serve as a rebuke against the Trump Administration and its merciless crusade to tear families apart,” Holder said in a statement.

The judge ruled after hearing arguments earlier Tuesday, when he put a government lawyer on the spot over the effort by immigration authorities to enforce a 2010 deportation order. He questioned the need to detain and quickly deport Villavicencio, who’s 35 years old.

“Well, the powerful are doing what they want, and the poor are suffering what they must,” the judge said after hearing Assistant U.S. Attorney Joseph Cordaro defend the government’s actions.

“I mean, is there any concept of justice here or are we just doing this because we want to?” the judge asked. “Why do we want to enforce the order? It makes no difference in terms of the larger issues facing the country.”

Cordaro argued for the case to be transferred to New Jersey because Villavicencio is detained there. He said legal precedent dictated that New Jersey was the proper venue, an argument the judge rejected.

Cordaro said Villavicencio would still be able to pursue his application to become a legal U.S. resident after he is deported.

The case has attracted widespread attention amid a crackdown by the administration of President Donald Trump on illegal immigration. Trump, a Republican, has said his policies are designed to keep the country safe.

Gov. Andrew Cuomo, a Democrat, said the federal government has “cruelly” kept Villavicencio from his wife, Sandra Chica, and two daughters “for no legitimate reason.”

Villavicencio was arrested on June 1 while making a delivery to the garrison in Fort Hamilton. When he arrived at Fort Hamilton, guards requested identification, and he produced a city identification card. A background check showed he had been ordered to leave the United States in 2010 but stayed.

Villavicencio’s attorney says he still faces a long process to gain legal status which could take at least a year.

(© Copyright 2018 CBS Broadcasting Inc. All Rights Reserved. The Associated Press contributed to this report.)