The Obama administration has told schools to allow transgender pupils to use the toilets that match their chosen gender identity.
Attorney General Loretta Lynch said it would protect transgender pupils from discrimination and peer harassment.
She said schools may face lawsuits or lose federal aid if they do not comply.
The federal government is fighting the state of North Carolina in court over a law requiring people to use toilets according to their gender at birth.
However the Obama administration education and justice departments say public schools must respect transgender pupils’ gender identity even if their education records or identity documents indicate a different sex.
“There is no room in our schools for discrimination of any kind, including discrimination against transgender students on the basis of their sex,” Ms Lynch said.
Campaigners hailed the move.
“This is a truly significant moment not only for transgender young people but for all young people, sending a message that every student deserves to be treated fairly and supported by their teachers and schools,” said Chad Griffin from Human Rights Campaign, a gay, lesbian and transgender rights organisation.
A new gender identity comes into force as soon as a parent or guardian notifies the school that their child’s identity “differs from previous representations or records” and must be respected even if it makes others uncomfortable, the directive says.
Ms Lynch said North Carolina’s new state law had echoes of policies of racial segregation and efforts to deny gay couples the right to marry.
The federal government and the state are suing each other over the law, which the federal authorities say violates the Civil Rights Act.
However, many businesses and entertainers have criticised the measures as discriminatory.
Musicians have cancelled concerts in the states and several companies have pledged to curtail their business in North Carolina.
Last month a US appeals courts ruled that a Virginia school policy that barred a transgender pupil from using the boys’ toilet was discriminatory.