LOS ANGELES — Concerned that thousands of migrant children in federal detention facilities could be in danger of contracting the coronavirus, a federal judge in Los Angeles late on Saturday ordered the government to “make continuous efforts” to release them from custody.

The order from Judge Dolly M. Gee of the United States District Court came after plaintiffs in a long-running case over the detention of migrant children cited reports that four children being held at a federally licensed shelter in New York had tested positive for the virus.

“The threat of irreparable injury to their health and safety is palpable,” the plaintiffs’ lawyers said in their petition, which called for migrant children across the country to be released to outside sponsors within seven days, unless they represent a flight risk.

There are currently about 3,600 children in shelters around the United States operated under license by the federal Office of Refugee Resettlement, and about 3,300 more at three detention facilities for migrant children held in custody with their parents, operated by the Immigration and Customs Enforcement agency.