The Obama administration on Friday directed schools across the nation to provide transgender students with access to suitable facilities — including bathrooms and locker rooms — that match their chosen gender identity.

The move, which affects all public schools and most colleges and universities that receive federal funds, plunges the administration even further into the country’s ongoing contentious debate over transgender rights.

The directive comes from two top administration officials: Catherine E. Lhamon, the assistant secretary of education for civil rights, and Vanita Gupta, head of the Justice Department’s Civil Rights Division. It put state and local officials and higher-education institutions on notice that they risk losing federal education aid if they limit students to areas or teams based on their gender assigned at birth.

The action was taken just days after the Justice Department and the state of North Carolina filed dueling lawsuits over a new law requiring individuals in that state to use bathrooms based on their birth gender.

Citing Title IX, which prohibits sexual discrimination at educational institutions that receive federal funding, the two officials warn that the obligation “to ensure nondiscrimination on the basis of sex requires schools to provide transgender students equal access to educational programs and activities even in circumstances in which other students, parents, or community members raise objections or concerns.

“As is consistently recognized in civil rights cases, the desire to accommodate others’ discomfort cannot justify a policy that singles out and disadvantages a particular class of students,” said the letter, which was obtained by The Washington Post.

The move prompted an immediate backlash from Republican officials across the country, though GOP members of Congress have largely refrained from weighing in on the legal tug of war between North Carolina and the administration that began last week.

Elizabeth Schultz, an outspoken conservative on the Fairfax County School Board in Virginia, said the guidance could infringe on some students’ religious convictions. In May 2015, Schultz voted against a move, which ultimately passed, to expand nondiscrimination protections in the district to transgender students. “Is there nothing that the federal government doesn’t dictate?” she asked.

Sen. Ben Sasse (R-Neb.) echoed the refrain in a tweet from his personal account: “Is there any issue the Obama Administration believes can be left to state and local government?”

Likely GOP presidential nominee Donald Trump, who has not been as critical of transgender protections as other Republicans, criticized the directive on ABC Friday, saying, “Well, I believe it should be states’ rights and the state should make the decision. They’re more capable of making the decision.”

The New York Times first reported the planned guidance Thursday evening.

For the most part, state and local officials have reversed course when threatened with the loss of federal funds over their treatment of transgender students. In 2013, the Education Department reached a settlement with the school district of Arcadia in California, on a dispute over whether the district violated Title IX by requiring a student who transitioned to being male to change clothes and use the bathroom in the nurse’s office.

In December, the school district in Palatine, Ill., agreed to allow a transgender girl to use the girls’ locker room after the Education Department threatened to withhold $6 million in federal funds.

Still, White House officials said Thursday that the administration will not halt funding to North Carolina until its court battle over the state’s “bathroom bill” is resolved.

Legal challenges on this issue are still wending their way through the courts: Last month, the U.S. Court of Appeals for the 4th Circuit ruled that a discrimination lawsuit filed by a transgender high school student against his school board for banning him from the boys’ bathroom can move forward.

On Thursday night, Gavin Grimm, the transgender student in Gloucester County, Va., who won the right to challenge his school, welcomed the administration’s action.

“I am so happy that with this new guidance, transgender students across the country have a new tool to ensure they are treated with dignity and respect at school,” said Grimm, a client of the American Civil Liberties Union. “This guidance would have made a big difference in my life, and I’m happy that kids will be free to use the bathroom that reflects who they are.”

The 4th Circuit’s ruling, along with the threat of new lawsuits from groups such as the ACLU and the Transgender Law Center, have already influenced other schools across the country. Horry County schools in South Carolina recently decided to allow transgender students to use the bathroom that corresponds with their gender identity, citing the ruling in Grimm’s case.

The National Association of Secondary School Principals, which asked the administration to issue comprehensive guidance on transgender students, said it was glad that the Education Department was “taking a stand” on the issue.

“The principal’s most important role is to create a climate and culture in which each student feels valued,” said Michael Allison, the association’s president. “There are countless reasons we could declare it impractical to address the needs of transgender students. None of those obstacles excuse us from doing the right thing.”

Komensky Elementary School’s principal, Jeremy Majeski, whose school is less than an hour from Palatine, Ill., said that his district has so far made decisions about how to treat transgender students on a case-by-case basis, in consultation with their parents. But school districts aren’t experts in gender identity, and so they need expert help. “To be able to lean on people who have done this before, it’s important.”

But Francisco Negron, general counsel for the National School Board Association, said despite the letter, some school officials remain in a bind in states where local laws and rules conflict with the Obama administration’s position.

“I don’t think the position expressed by the department does anything to solve the untenable position that school districts find themselves in when we have to deal with other state laws like H.B. 2 in North Carolina,” he said, referring to the recently passed state law that requires people to use bathrooms that correspond with the sex on their birth certificate.

Moriah Balingit and Mike DeBonis contributed to this report.