A federal judge in Washington, D.C., granted an injunction Monday that temporarily freezes President Trump’s effort to roll back open transgender military service.

The order blocks the Defense Department and Coast Guard from barring transgender service and recruiting, based on an order by Trump in August, while the court hears a lawsuit by a group of active-duty troops, a Naval Academy midshipman and a teenage ROTC member.

However, the judge ruled with the administration by allowing it to continue with plans to stop gender transition surgeries for troops, saying none of the plaintiffs was at risk of being harmed by the move.

The Doe v. Trump case in D.C. district court is one of four lawsuits filed against Trump, Defense Secretary Jim Mattis and other top defense officials following the president's July tweets announcing an end to active service by transgender troops "in any capacity," and an Aug. 25 memorandum ordering the Pentagon and Coast Guard to come up with a plan to revert to the policy in place before the Obama administration declared open service in 2016.

“We are thrilled for our plaintiffs and for other transgender service members, whose lives have been devastated since President Trump tweeted the ban,” Shannon Minter, a lead attorney in the case and the legal director of the National Center for Lesbian Rights, wrote in an email response to the Washington Examiner.

White House press secretary Sarah Sanders on Monday declined to comment on the injunction, but said it is being reviewed by the Department of Justice, which is handling the case. The administration also faces lawsuits in Maryland, California and Washington state.

The preliminary injunction decision by U.S. District Judge Colleen Kollar-Kotelly is a setback for Trump, who surprised many in the Pentagon and on Capitol Hill with his July tweets, and an indication that the court believes the plaintiffs have a chance of prevailing in the suit.

Kollar-Kotelly wrote that the plaintiffs are arguing that Trump's decision is "not genuinely based on legitimate concerns regarding military effectiveness or budget constraints, but are instead driven by a desire to express disapproval of transgender people generally."

The argument appears to have merit, she wrote, due to a variety of factors, including "the sheer breadth of the exclusion ordered by the directives, the unusual circumstances surrounding the President’s announcement of them, the fact that the reasons given for them do not appear to be supported by any facts, and the recent rejection of those reasons by the military itself."

The military under former President Barack Obama studied the issue and concluded that transgender troops should not be barred from service before former Defense Secretary Ash Carter changed the personnel policy. A Rand Corp. study during that time estimated about 1,300 to 6,600 transgender troops were serving and that about .1 percent of the total force might seek gender transition healthcare that might disrupt their service.

In June, Mattis declared a six-month delay in the start of the military's recruitment of transgender troops, which was to be the last leg of the integration plan, and several weeks later Trump issued a string of tweets announcing the ban.

"After consultation with my Generals and military experts, please be advised that the United States Government will not accept or allow transgender individuals to serve in any capacity in the U.S. Military," Trump wrote. "Our military must be focused on decisive and overwhelming victory and cannot be burdened with the tremendous medical costs and disruption that transgender in the military would entail.

Mattis later convened a panel of experts whose job was to come up with a plan to implement Trump's directive by next spring.