An Afghan family of five that had received approval to move to the United States based on the father’s work for the American government has been detained for more than two days after flying into Los Angeles International Airport, a legal advocacy group said in court documents filed on Saturday.

A federal judge in Los Angeles issued on Saturday evening a temporary restraining order to prevent the mother and children from being transferred out of the state. The order, by Judge Josephine L. Staton of the United States District Court for the Central District of California, arrived as they were about to be put on a plane to Texas, most likely bound for a family detention center there, lawyers said.

The scene at the airport was “chaotic, panicked; it was a mess,” said Lali Madduri, a lawyer with the firm Gibson Dunn, which is representing the family pro bono. “The whole time the children are crying, the woman is crying. They can’t understand what’s going on.”

The father had arrived on Thursday with his wife and three children, ages 7, 6 and 8 months, on Special Immigrant Visas, according to the lawyers’ habeas corpus petition filed on Saturday in Federal District Court in Los Angeles. Those visas were created by Congress for citizens in Iraq and Afghanistan who have helped the United States military or government as drivers, interpreters or in other jobs — work that often makes them targets in their home countries.