Instead, after the girl was apprehended by Immigration and Customs Enforcement agents in a parking lot, she was eventually transferred to New York and held by the Office of Refugee Resettlement, which handles custody of unaccompanied minors. The lawyer for the teenager had petitioned the federal court for her release, and US District Judge Leo T. Sorokin ordered agents begin her return to Massachusetts by Thursday morning. The girl is from Brazil and entered the US on a visitor visa in 2019, according to court documents, and has been here since. Her mother is deceased and her father is not involved in her life, according to her attorney, Andrew Lattarulo, who said she was living with her older brothers, who are US citizens. It’s unclear whom the girl was with at the time of her apprehension. A witness told the Globe he encountered her two older brothers at the scene trying to get her released. In a statement to the Globe, Department of Homeland Security Deputy Assistant Secretary Lauren Bis said ICE had not arrested the girl, but rather “rescued her from suspected gang members.”The girl was found with the men when ICE was conducting a “targeted operation” to arrest two suspected Primeiro Comando da Massachusetts gang members from Brazil who were in the country illegally, Bis said. She identified the men as Igor Jose Cordeiro Ferreira and Lucas Da Silva Senes De Almeida.Cordeiro Ferreira, 28, entered the US unlawfully in 2022, and Da Silva Senes De Almeida, 25, did not leave the US after his visa expired in 2024, according to DHS.Bis said the vehicle used by the two men was connected to an alleged home invasion in Walpole earlier in March, Bis said. The teenager did not identify the men as legal guardians, and “upon further investigation, special agents confirmed that the 14-year-old girl had no familial relationship to either individual,” Bis said. The girl was placed in the custody of the refugee office within hours, according to DHS, “to ensure the safety and security of the minor.” Earlier in the day Wednesday, as information about the case unfolded, Lattarulo said the girl had no known criminal history and he did not know why she was being detained.“Federal agents took this fourteen-year-old child into custody and continue to detain her in a federal building without any indication that the government has complied with the statutory and constitutional limits governing the detention of minors in immigration custody,” according to the habeas petition he filed with the court.“If this was a state charge, why weren’t the police involved? Why wasn’t DCF called?” Lattarulo asked in an interview. “Why is the move always, ‘arrest this child and then move her out of state’?”He said that after detaining her, officials took her cellphone and did not provide her with adequate meals. “We’re talking nearly 20 hours, no sleep, no food. I mean, that’s insane,” Lattarulo said.In a hearing on the case on Wednesday afternoon, Ray Farquhar, a lawyer from the US attorney’s office, said that this was an “atypical case,” and that he was trying to work together with Lattarulo to “find resolution” for it. If a guardian for the girl had come forward, Farquhar said, she would have been able to leave with that person. “This is not a situation, your honor, in my understanding, that the government is holding on to this individual with any intent to remove her from the country,” Farquhar told the judge.Sorokin appeared surprised the girl wasn’t put in the custody of the state Department of Children and Families instead of federal authorities. “It’s the first time in my 22 years as a federal judge ... that I’ve heard of federal agents taking a juvenile into custody, where the only reason to take the juvenile into custody, seemingly, was that there wasn’t an appropriate person to release them to,” he said. Ordinarily, he said, federal authorities turn children “over to the state authorities for those kinds of things.”Lattarulo said in court the girl was living with her older brothers for the past month, and that he was looking to obtain a legal status for her available to juveniles who are abused, abandoned, or neglected by a parent.Lattarulo asked for her to be released to reside with her maternal aunt and uncle in Weymouth, who have a “more suitable home for her,” and can apply to be her guardians. Sorokin asked that the aunt, a US citizen, submit an affidavit that she’s seeking to be appointed temporary guardian, and ordered the girl be released to live with the aunt.Van Celedon, who works at a law firm in Marlborough, told the Globe he was driving near a Presbyterian church when he saw several cars with tinted windows and what looked like federal agents in the parking lot. He got out of his vehicle and encountered two young men who appeared to be in their early 20s and asked if they needed help. The men told Celedon that ICE agents had detained their 14-year-old sister during a traffic stop near their home, Celedon said, and that they were trying to get her released.Celedon also tried to communicate with the agents, but he said they would not tell him much except they were taking the girl to the police station in Marlborough. “As soon as I tried to approach them they were in a hurry to take off,” Celedon said.US Representative Ayanna Pressley said in a statement that the girl, who is her constituent, was “taken without justification or due process.”“She was held for hours in these places alone, scared, without adequate access to a phone or even a proper meal,” Pressley said.Pressley said the girl attended Brighton High School, though Boston Public Schools said in a statement that the teenager is not currently enrolled in the school district. Marlborough Public Schools said she was not enrolled in its schools, either.Governor Maura Healey also denounced the girl’s detention. “It is absolutely unacceptable that ICE detained a 14-year-old girl in a church parking lot in Marlborough and abruptly moved her out of Massachusetts,” the governor said. “This is a child. ICE never should have detained her like this and separated her from her support system and legal counsel. And it shouldn’t have taken a federal court order for her to be returned.”Giulia McDonnell Nieto del Rio can be reached at giulia.mcdnr@globe.com. Follow her @giuliamcdnr. Marcela Rodrigues can be reached at marcela.rodrigues@globe.com.