A US federal judge in Boston on Friday gave the Trump administration three weeks to “rectify the mistake” it made by deporting a college student to Honduras while she was traveling home to visit her family for Thanksgiving as he recommended it issue her a student visa.

The US district judge, Richard Stearns, imposed the deadline after a lawyer for the administration earlier this week apologized for having violated a court order that should have prevented 19-year-old Any Lucia López Belloza from being sent to Honduras. She is a Honduran national who was brought to the United States by her mother when she was eight while seeking asylum.

“There is happily no one-size-fits-all solution for seeing that justice be done in what all agree was an amalgam of errors that ended badly for Any,” he said.

Stearns said the “simplest solution” would be for the US state department to issue her a visa. The alternative, he said, would be for him to order the Trump administration to arrange for López Belloza’s return, with a threat of holding the government in contempt if it refused.

He gave the administration 21 days to inform him of how it will proceed. The justice department declined to comment. Her lawyer did not respond immediately to a request for comment.

López Belloza, a freshman at Babson college in Massachusetts, was arrested on 20 November at Boston’s Logan airport while trying to travel home to Texas to surprise her family for Thanksgiving.

Her lawyer sued in Massachusetts to challenge her detention, and a judge issued an order on 21 November barring López Belloza from being deported or transferred out of the state for 72 hours.

But by that time, López Belloza had already been moved to Texas. She was sent to Honduras the next day and remains there with her grandparents.

Stearns, who was appointed by Bill Clinton, said because López Belloza was outside of Massachusetts by the time her lawyer sued, he lacked jurisdiction to hear her overall case going forward.

But he said the government retained the ability to remedy the “tragic (and preventable) mistake” of violating the court’s order.

A lawyer for the government on Tuesday apologized for what he said was a “mistake” by an officer with Immigration and Customs Enforcement who failed to properly flag the court order because he thought it no longer applied as she was out of Massachusetts.