President Trump announced in July that transgender troops would no longer be allowed to serve in any capacity in the military. But almost half a year later, and after numerous legal motions, the Pentagon is poised to begin accepting new transgender troops for the first time beginning Jan. 1.

The turnaround shows how the Trump administration has been hit with a series of early legal setbacks as it tries to defend the president’s ban from federal lawsuits by transgender troops and rights groups, and that this round of challenges and responses is only the beginning.

So far, judges have sided with opponents of the ban in two federal lawsuits. The initial rulings have frozen Trump’s transgender policy orders and ordered Defense Secretary Jim Mattis, who is also a target of the suits, to start the enlistments. Two other courts were also set to rule on injunctions.

“These are very powerful decisions, so far they are unanimous in concluding that the ban is likely to be held unconstitutional,” said Shannon Minter, legal director for the National Center for Lesbian Rights and a lead attorney in two of the lawsuits.

But the legal battle over Trump’s effort to roll back the Obama administration policy of open transgender service may just be getting underway. The Justice Department was weighing its legal options Monday and none of the federal cases filed against the president in D.C., Maryland, California, and Washington state has yet gone to trial.

The most recent and significant legal blow for the administration came from a D.C. federal court judge’s ruling on Monday denying the Justice Department's emergency request that sought to delay the transgender enlistments past Jan. 1.

The department argued that the military would be “seriously and irreparably harmed” if forced to accept new transgender troops next month.

Judge Colleen Kollar-Kotelly had already granted an injunction in October to Minter’s plaintiffs in the Doe v. Trump case, who include six anonymous transgender service members, a midshipman at the U.S. Naval Academy and an ROTC student.

The original order, which remains in effect while the case is heard, came with a stinging criticism of the reasoning behind Trump’s new transgender policy and how it came about.

The president announced the ban in July via a series of tweets, citing “tremendous medical costs and disruption” caused by open service. In August, he ordered the Pentagon to abandon earlier plans to begin transgender recruiting Jan. 1, and to eliminate coverage for gender reassignment surgeries and deal with current transgender troops by March.

Kollar-Kotelly said her injunction blocking a new transgender policy was justified due to “the sheer breadth of the exclusion ordered by [Trump’s] 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 Justice Department followed up by asking the court if Mattis still had the authority to delay transgender enlistments and commissioning beyond Jan. 1 despite the injunction. Kollar-Kotelly said "no" in her clarification order on Nov. 27.

A department's subsequent motion for an emergency stay was rejected by Kollar-Kotelly on Monday, and immediately after the ruling the Pentagon said it was going to carry out the judge's order and begin the enlistments.

“If the Pentagon is going to follow the law, they are going to figure out a way to access transgender applicants for military service at the beginning of next year,” said Alex Wagner, an adjunct professor at Georgetown University Law Center. Wagner served as chief of staff to former Army Secretary Eric Fanning, who helped write the Obama administration transgender policy and has supported the lawsuits of Trump ban opponents.

However, the Doe v. Trump injunction did not address Trump’s order to eliminate military coverage of gender reassignment surgeries. Kollar-Kotelly ruled that none of the plaintiffs in that case would be affected.

But a federal judge just across the border in Maryland granted another injunction last month to plaintiffs in the Stone v. Trump lawsuit that specifically prohibits the Pentagon from changing the medical policy. Such operations can now be authorized by the military.

“In the Stone case, the judge found that our plaintiffs did have standing so his injunction explicitly applies to the surgery ban also,” said Josh Block, a staff attorney with the American Civil Liberties Union who is handling the Maryland case.

The Stone lawsuit was filed in August by four active-duty and two National Guard transgender troops.

So far, the Justice Department has argued that the lawsuits are premature because Mattis has not yet settled on any final transgender policy for the military and therefore plaintiffs in cases such as Doe v. Trump cannot prove they will be harmed.

Trump ordered Mattis to abandon transgender enlistments but also gave the secretary a February deadline to finalize the other parts of the transgender policy, including whether current transgender troops will be separated.

The Pentagon had spent the last three months working that. In August, the defense secretary created a panel of senior enlisted advisers, defense secretaries, undersecretaries, medical professionals and others that has met weekly.

It had previously directed media questions about its plans and the lawsuits to the Justice Department. But last week, the Pentagon told the Washington Examiner it was taking steps to prepare for transgender enlistment on Jan. 1 due to the legal developments.

The legal situation could soon become more complicated.

A judge in Washington state was set to issue a decision Monday on another injunction in the Karnoski v. Trump lawsuit, said Peter Perkowski, counsel for the rights group OutServe-SLDN who is an attorney for plaintiffs in the case.

“I don’t know what the scope of her injunction would look like if she were to grant one,” Perkowski said.

There was also hearing Monday on an injunction in the California case of Stockman v. Trump that is also opposing the ban, said Minter, who is a lead attorney. The state of California recently signed on as a plaintiff along with the four active-duty and three prospective enlistees who filed the lawsuit.

The judge’s decision on whether to grant a third injunction on Trump’s transgender ban is expected to follow soon after, Minter said.

“What would be the best possible development from our point of view is that Secretary Mattis … confirms there is no reason for the ban and President Trump would rescind that order,” he said.