WASHINGTON (Reuters) - President Donald Trump said on Wednesday he would ban transgender people from the U.S. military, a move appealing to some in his conservative political base but creating uncertainty about the fate of thousands of transgender service members.

The surprise announcement by Trump, who as a presidential candidate last year vowed to fight for lesbians, gays, bisexuals and transgender people, came in a series of morning Twitter posts. It drew condemnation from rights groups and some lawmakers in both parties as politically motivated discrimination but was praised by conservative activists and some Republicans.

The administration has not determined whether transgender individuals already serving in the military would be immediately thrown out, a point the White House and Pentagon have yet to decide, Trump spokeswoman Sarah Sanders said.

A transgender ban would reverse Democratic former President Barack Obama’s policy and halts years of efforts to eliminate barriers to military service based on sexual orientation or gender identity.

“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 tweeted, without naming any of the generals or experts.

“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,” he said.

Sanders said Trump had “extensive discussions with his national security team,” and Defense Secretary Jim Mattis was informed after the president made the decision on Tuesday.

“This was about military readiness,” Sanders told a briefing. “This was about unit cohesion. This was about resources within the military, and nothing more.”

The Pentagon earlier referred questions about Trump’s decision to the White House.

Critics said the health costs of caring for transgender service members were a tiny portion of the military’s healthcare budget and Trump’s policy change was based on prejudice.

His action unleashed a torrent of legal threats from civil liberties advocates seeking plaintiffs willing to challenge the ban in court and sparked a protest by hundreds who rallied outside an armed forces recruiting station in Manhattan’s Times Square.

“We are in a crisis. This is a dark day for everyone,” Brad Hoylman, New York’s sole openly gay state senator, said as he addressed the crowd, which carried “Resist” signs amid chants of: “Hey-hey, ho-ho, Donald Trump has got to go.”

A MATTER OF TIMING

Trump’s tweet caught some White House officials by surprise.

A senior administration official said Trump had been determined to act for a while but the question was the timing, with advisers split on whether to conduct reviews before announcing the move.

The announcement at least temporarily changed the subject in Washington, where Trump’s administration faces investigations into his presidential campaign’s contacts with Russia and has struggled to win major legislative victories.

It was not the first time Trump has targeted transgender people since taking office in January. In February, he rescinded protections for transgender students put in place by Obama that had let them use bathrooms corresponding with their gender identity.

Senate Armed Forces Committee Chairman John McCain - the most prominent military veteran in Congress, who was a Navy pilot and prisoner of war during the Vietnam War - called Trump’s announcement unclear and inappropriate until a Pentagon study on the issue is completed and reviewed by Mattis, the military leadership and lawmakers.

Tony Perkins, president of the Family Research Council advocacy group, was among those praising Trump, saying, “Our troops shouldn’t be forced to endure hours of transgender ‘sensitivity’ classes and politically correct distractions.”

Under Obama, the Pentagon last year announced it was ending its ban on transgender people serving openly, calling the prohibition outdated.

The Defense Department had been expected to begin formally allowing transgender people to enlist this year. But Mattis on June 30 approved a six-month delay in that step.

Slideshow ( 14 images )

Transgender service members already number about 2,500 active-duty personnel, with about 1,500 more in the military reserves, according to a RAND Corporation think tank study cited last year by Obama’s defense secretary, Ash Carter.

“To choose service members on other grounds than military qualifications is social policy and has no place in our military,” Carter said on Wednesday, noting the existing ranks of transgender individuals serving “capably and honorably.”

Advocacy groups said Trump’s policy was open to legal challenge under the U.S. Constitution’s guarantee of equal protection under the law.

“CHEAP POLITICAL POINTS”

American Civil Liberties Union attorney Joshua Block said Trump had rejected the “basic humanity” of transgender service members.

Slideshow ( 14 images )

“There are no cost or military readiness drawbacks associated with allowing trans people to fight for their country,” Block said. “The president is trying to score cheap political points on the backs of military personnel who have put their lives on the line for their country.”

The House of Representatives’ top Democrat, Nancy Pelosi, noted that a Pentagon-commissioned study determined the cost of providing medically necessary transition-related care involving transgender service members would amount to about one-100th of 1 percent of the military’s healthcare budget.

The study put the cost at $2.4 million to $8.4 million a year of the more than $50 billion the Defense Department spends on healthcare.

“Once again, President Trump has shown his conduct is driven not by honor, decency, or national security, but by raw prejudice,” Pelosi said.

Retired Colonel Sheri Swokowski, 67, the highest-ranking openly transgender veteran, joined the criticism.

“Transgender people are serving today knowing that their leader frankly doesn’t trust them,” she said. “The bottom line is that this does great harm to people who simply want to serve their country.”

U.S. Representative Ileana Ros-Lehtinen, a Republican whose son is transgender, said on Twitter: “No American, no matter their sexual orientation or gender identity, should be prohibited from honor + privilege of serving our nation.”

Transgender celebrity Caitlyn Jenner defended “patriotic transgender Americans” in the military and asked Trump on Twitter, “What happened to your promise to fight for them?”

Canada’s military also took to Twitter on Wednesday to say it welcomes citizens “of all sexual orientations and gender identities,” adding the hashtag #DiversityIsOurStrength.

But Vicky Hartzler, a Republican congresswoman, praised Trump for changing Obama’s “costly and damaging policy.”

The U.S. military’s ban on gays serving openly in the armed forces ended under Obama in 2011 after Congress passed legislation in 2010 reversing a law dubbed “don’t ask, don’t tell” that had forced the ouster of thousands of service members and others to hide their sexual orientation.

The Pentagon under Obama also opened all combat roles in the military to women.

The U.S. military at times has been in the vanguard of social progress. Trump’s action came on the 69th anniversary of Democratic President Harry Truman racially integrating the armed forces, years before the 1950s and 1960s civil rights battles.