WASHINGTON — President Trump’s order late Friday that bans transgender individuals from serving in the armed forces except under “limited circumstances” sets the stage for a legal battle and an eventual Supreme Court ruling on whether the government can discriminate against people because of their gender status.

The White House order follows through on Trump’s promise to reverse an Obama-era policy that allowed transgender troops to serve openly for the first time.

Individuals with a history or diagnosis of gender dysphoria — that is, people who identify as being a gender other than their gender at birth — are generally ineligible for military service, the new order says, arguing that they “present considerable risk to military effectiveness and lethality.”

The new ban will apply to transgender individuals who require substantial medical treatment, including medication and surgery.

The policy shift, announced late Friday evening, hours after Trump had left for a weekend in Florida, is the latest twist in a politically fraught controversy that began unexpectedly last summer when he called, in a tweet, for banning transgender troops, catching the Pentagon off guard.

The new order bars the Pentagon from enlisting recruits who have undergone gender transition treatment and could require kicking out some active-duty troops. However, the order gives Defense Secretary James N. Mattis leeway to retain those who have served openly since doing so was authorized.

Current transgender service members could remain in the armed forces if they have been “stable for 36 consecutive months in their biological sex” before joining the military and are able to deploy overseas, according to a memo by Mattis outlining the new policy.

Service members diagnosed with gender dysphoria after joining the military could remain if they do not undergo gender reassignment, the memo said. Troops diagnosed while the Obama policy was in effect “may continue to serve in their preferred gender” and to receive treatment.

Transgender individuals without a history or diagnosis of gender dysphoria are free to serve, it said.

Administration officials say the order creates an objective standard for prohibiting transgender individuals from serving — a contention certain to be tested in court.

However, the order will have no immediate effect, lawyers said, because four federal district judges issued nationwide orders last year that blocked Trump’s original, more far-reaching proposal from taking effect.

In December, two U.S. appeals courts — in Washington, D.C., and Virginia — refused emergency requests from administration lawyers to lift lower court orders and maintain an enlistment ban.

“It must be remembered,” the U.S. Court of Appeals for the District of Columbia Circuit said, that the transgender individuals who went to court seek “to serve their nation with honor and dignity, volunteering to face extreme hardships, to endure lengthy deployments and separation from family and friends and to willingly make the ultimate sacrifice of their lives if necessary.”

The Supreme Court has not ruled on transgender rights. In its only case on the issue, in 2016, the justices in a brief order set aside a lower court’s ruling that would have required a Virginia high school to allow a transgender boy to use the boys’ restroom.

Administration lawyers argue that the courts must give special deference to the military. They say the Pentagon’s leaders and military commanders are best suited to decide who can serve.

But advocates for transgender rights say the White House policy discriminates against all transgender persons without regard to their ability to serve.

The new order “categorically bans transgender people from service, with no legitimate basis,” said Jennifer Levi, who directs the transgender rights project for Gay and Lesbian Advocates and Defenders in Boston.

“This policy deems transgender people unfit for service. It’s basically an absolute ban. We will continue to challenge this because there is no military justification for it. And I expect ultimately this will be resolved in the U.S. Supreme Court,” Levi said.

Shannon Minter, legal director for the National Center for Lesbian Rights in San Francisco, called the new policy “exactly the discriminatory, categorical ban that four federal courts have already barred from going forward.”

The Pentagon keeps no figures on transgender personnel. Outside groups estimate there are 1,300 to 15,000 transgender troops in the military, which has an active-duty force of about 1.3 million.

White House Press Secretary Sarah Huckabee Sanders said, “This new policy will enable the military to apply well-established mental and physical health standards — including those regarding the use of medical drugs — equally to all individuals who want to join and fight for the best military force the world has ever seen.”

Trump’s effort to bar transgender service members has faced intense pushback in Congress and the courts, raising doubts about whether the president would proceed with his sweeping ban.

Other outside groups advocating for transgender troops and Democrats in Congress quickly assailed the revised order.

“This policy is a thinly veiled and feeble attempt by the Trump-Pence administration to justify the unnecessary discrimination of qualified patriots in order to advance their own personal agendas and in defiance of the administration’s top military leadership. This plan is riddled with blatant animus, bigotry and ignorance but conveniently void of any foundational bases or facts,” said Matt Thorn, president of OutServe-SLDN, an LGBTQ rights group.

The House Democratic minority leader, Rep. Nancy Pelosi of San Francisco, tweeted: “No one with strength & bravery to serve in the U.S. military should be turned away because of who they are. This hateful ban is purpose-built to humiliate our brave transgender members of the military who serve with honor & dignity.”

The requirements make it difficult for a transgender recruit to qualify. But they closely track conditions imposed by the Obama administration in 2016, when the Pentagon initially lifted its ban on transgender individuals serving openly in the military.

Mattis has said that transgender troops would have to be capable of deploying for at least a year to an overseas war zone, the same policy the Pentagon plans to impose on all troops to remain in the military.

That would reverse the current policy, since 2016, of allowing transgender troops to serve openly.

A major change of Pentagon policy is typically subject to months, if not years, of study and legal vetting before it’s rolled out. In his policy announcement he tweeted last year, Trump told Mattis only a day before and didn’t consult senior military commanders beforehand.

In an executive order following his tweet, Trump directed the Pentagon to develop guidance on returning to “the long-standing policy and practice” of barring military service by transgender individuals.

But it also let Mattis issue a recommendation on whether self-declared transgender members of the military could continue to serve, which he delivered last month in a private conversation with Trump.

The White House had given Mattis until last month to submit a plan on how the ban would be implemented, including how it would handle thousands of transgender soldiers, sailors, Marines and airmen.

Under the Obama policy, transgender individuals were to be allowed to openly enlist in the military for the first time by Jan. 1, 2018. But Mattis waived that deadline for a policy review.

david.cloud@latimes.com

david.savage@latimes.com