Bill Clark/CQ Roll Call via Getty Images Rep. Vicky Hartzler (R-Mo.) is pushing a proposal to deny medically necessary care to transgender people in the military. Why?

WASHINGTON ― The House on Thursday unexpectedly defeated a proposal to deny medically necessary health care to transgender people in the military ― a win for LGBTQ rights advocates who were bracing for a blow.

Rep. Vicky Hartzler (R-Mo.) proposed an amendment to the 2018 national defense authorization bill that would prevent transgender military personnel from getting medical treatment such as hormone therapy or gender reassignment surgery. There are as many as 6,630 transgender people in active military service, per a RAND Corp. study.

Given the House’s Republican majority, the proposal was expected to pass, despite outcry from Democrats. In a twist, though, the House rejected it, 209-214. Twenty-four Republicans sided with all Democrats in bringing it down.

Click here for a breakdown of how every lawmaker voted. Reps. Darrell Issa (R-Calif.) and Barbara Comstock (R-Va.), both facing challenging re-election campaigns, were among those who voted against the amendment.

There’s one detail in particular that may have nudged some Republicans to oppose the measure: Defense Secretary James Mattis personally called Hartzler ahead of the vote and asked her to yank her amendment, a senior House Democratic aide told HuffPost.

A Defense Department spokesman offered no details on such a call, but said conversations between Mattis and members of Congress are private. A Hartzler spokesman did not respond to a request for comment.

Here’s the text of Hartzler’s amendment:

House Rules Committee

LGBTQ rights advocates celebrated the surprising victory shortly afterward.

“This was a horrifying, vicious attack on service members and military family members, and our families were beside themselves in fear,” said Ashley Broadway-Mack, president of the American Military Partner Association. “It would have been beyond unconscionable to rip away the critically important health care of transgender military family members and service members — care that their doctors believe is medically necessary — and would have severely harmed thousands of military families and undermine military readiness.”

Openly transgender people have served in the military since October 2016. The costs of providing them with gender transition-related medical care are relatively low: RAND estimates 30 to 140 people would seek new hormone treatments per year, and 25 to 130 would seek gender transition-related surgeries. That amounts to a 0.04 to 0.13 percent increase in health care expenditures, per RAND.

Despite that data, Hartzler argued during the debate that it’s too expensive for the military to cover the added medical costs for transgender troops. “It decreases deployability of soldiers” and ends up “diverting money from other defense priorities,” she said.

Rep. Duncan Hunter (R-Calif.), who supported her amendment, was more callous. “Choose what gender you are before you join,” he declared. “Figure out whether you’re a man or a woman before you join.”

The American Medical Association has emphasized the medical necessity of mental health care, hormone therapy and gender-transition surgery as forms of therapeutic treatment for people diagnosed with gender dysphoria, a “serious medical condition” that stems from the distress a person feels when his or her gender identity does not correspond with his or her birth sex. Not all transgender people are diagnosed with gender dysphoria; some don’t experience that distress.

When Hartzler’s amendment was attached to the defense authorization bill late Wednesday night in a House Rules Committee hearing, Rep. Jared Polis (D-Colo.) tried to strip it out. Every Republican present voted no.

Those members were Reps. Pete Sessions (Texas), Tom Cole (Okla.), Rob Woodall (Ga.), Michael Burgess (Texas), Doug Collins (Ga.), Bradley Byrne (Ala.), Dan Newhouse (Wash.) and Liz Cheney (Wyo.).

This article has been updated to reflect the outcome of the House vote.

CORRECTION: An earlier version of this article identified Barbara Comstock as representing Maryland instead of her actual state of Virginia.