In the latest twist of a winding legal case over worship in public school facilities, a federal appeals court ruled on Friday that New York City was allowed to prevent dozens of religious groups from holding services in the schools.

The ruling, by a panel of the United States Court of Appeals for the Second Circuit — which the city had asked to review a lower court’s decision — came one day after a federal judge directed the city to halt its plan to eject religious groups that that had been worshiping in public schools on weekends.

The appeals court said a temporary restraining order that the judge, Loretta A. Preska of United States District Court in Manhattan, issued on Thursday applied only to the plaintiff in the case before her, the Bronx Household of Faith, and not to other groups.

“The Department of Education is legitimately concerned about public schools being affiliated with a particular religious belief or practice,” Jane Gordon, a lawyer for the city, said.