A federal court in Washington has barred Donald Trump from changing the US government's policy on military service by transgender people.
The president announced in an August memo that he intended to reverse course on a 2016 policy that allowed troops to serve openly as transgender individuals.
He said he would order a return to the policy from before June 2016, under which service members could be discharged for being transgender.
US District Judge Colleen Kollar-Kotelly wrote that transgender members of the military who had sued over the change were likely to win their lawsuit and barred the Trump administration from reversing course.
She directed a return to the situation that existed before Mr Trump announced his new policy, saying the administration had provided no solid evidence for why a ban should be implemented.
The Trump administration may appeal against Judge Kollar-Kotelly's decision, but for now, the proposed ban remains unenforceable under her preliminary injunction.
"We disagree with the court's ruling and are currently evaluating the next steps," said Justice Department spokesman Lauren Ehrsam.
She reiterated the department's view that the lawsuit was premature because the Pentagon was still in the process of reviewing how the transgender policy might evolve.
One of the attorneys handling the lawsuit, Shannon Minter of the National Centre for Lesbian Rights, said the ruling was an enormous relief to his clients.
"Their lives have been devastated since Trump first tweeted he was reinstating the ban," Ms Minter said.
"They are now able to serve on equal terms with everyone else."
Mr Trump announced on Twitter in July that the government "will not accept or allow transgender individuals to serve in any capacity in the US Military".
He followed with an August memo directing the Pentagon to extend indefinitely a ban on transgender individuals joining the military, and gave Defence Secretary Jim Mattis six months to come up with a policy on "how to address" those who are currently serving.
Under the Obama administration, the Department of Defence had announced in 2016 that service members could not be discharged solely based on their gender identity.
Transgender individuals were to be allowed to enlist in the military in June 2017, a timeline initially delayed under the Trump administration to January 1 2018.
Ms Minter said the new court ruling means they will be able to enlist as of that date.
The Trump administration had asked the court to dismiss the lawsuit; Judge Kollar-Kotelly refused to do so, and Ms Minter said it is possible the case will go to trial.
One issue not directly addressed in Monday's ruling was whether federal funds should be used to pay for sexual reassignment surgeries for members of the military.
The administration has sought to prohibit such payments; Judge Kollar-Kotelly said she did not have jurisdiction to rule on the issue because none of the plaintiffs in the case established a likelihood of being impacted by that prohibition.
The lawsuit was filed in August by the National Centre for Lesbian Rights and GLBTQ Legal Advocates & Defenders on behalf of eight transgender individuals, including service members in the Air Force, Coast Guard and the Army, as well as students at the US Naval Academy and in the ROTC programme at the University of New Haven.
The Justice Department, in seeking the lawsuit's dismissal, said none of the plaintiffs had established that they will be impacted by current policies on military service.
The two advocacy groups who filed the lawsuit assailed that assertion.
They highlighted the uncertainty facing Regan Kibby, the transgender Naval Academy student who - because of Mr Trump's action - was unsure whether he would be able to join the Navy on graduation.
Judge Kollar-Kotelly said the plaintiffs clearly established that they would be harmed by the administration's directives.
She also contended that the plaintiffs were likely to prevail in arguing that the directives were unconstitutionally discriminatory - targeting transgender people without evidence that their service caused substantive problems for the military.
The directives "do not appear to be supported by any facts", the judge wrote.
The Pentagon has not released data on the number of transgender people currently serving, but a Rand Corporation study has estimated between 1,320 and 6,630, out of 1.3 million active-duty troops.