After two weeks in U.S. Immigration and Customs Enforcement custody, a 37-year-old Irish national who had been living in Montgomery County for more than a decade will be temporarily released on a judge’s orders.

Keith Byrne, of Springfield Township, was detained on his way to work the morning of July 10.

Byrne grew up in County Cork and came to the United States in 2007 through the visa waiver program. It allows visitors from participating countries to travel here easily for short stays, but closes off some opportunities to adjust their status if they overstay.

For a decade, Byrne had tried to obtain a green card through his marriage to Keren Bryne, a U.S. citizen from Northwest Philadelphia. He and Keren have two children together and are also raising Keren’s son from a previous relationship.

U.S. Citizenship and Immigration Services denied their petitions for an adjustment of his status, due to two marijuana possession citations he admitted getting when he lived in Ireland.

Even so, Keren Byrne said they had been in contact with USCIS on and off for the last decade, and had received no indication that Keith would be subject to arrest and removal. Marriage to a U.S. citizen is one of the few ways a person who crosses into the United States illegally, or who overstays a visa, can earn legal status — though it’s not guaranteed.

In an order filed Thursday, U.S. District Court Judge Christopher Connor compelled ICE to release Byrne for 30 days, so that he could ask a federal judge to review his most recent denial.

The family’s attorney, Tom Griffin, said they plan to argue USCIS violated the Administrative Procedures Act by failing to consider evidence and legal arguments supporting Keith’s case in the agency’s most recent determination.

Keren Byrne could not immediately be reached for comment.

In a statement, federal immigration enforcement officials reaffirmed their reasons for his arrest.

“In 2007, Keith Byrne, 37, a citizen of Ireland, entered the United States as a nonimmigrant under the Visa Waiver Program and failed to depart the United States under the terms of his admission,” said an ICE spokesman in the Philadelphia Field Office, who acknowledged that ICE is releasing Byrne from the Pike County Correctional Facility in accordance with the judge’s order.