“They created state-sponsored discrimination against transgender individuals who simply seek to engage in the most private of functions in a place of safety and security,” she said at a news conference in Washington. “None of us can stand by when a state enters the business of legislating identity and insists that a person pretend to be something or someone that they are not.”

Straying from her usual understated, lawyerly tone, Ms. Lynch, a North Carolina native, grew impassioned as she likened the fight to earlier battles over Jim Crow laws and laws against same-sex marriage.

“This is not the first time that we have seen discriminatory responses to historic moments of progress,” she said. Addressing transgender people, she added: “We see you. We stand with you, and we will do everything we can to protect you going forward.”

The Justice Department’s lawsuit, filed in a different federal court in the state, argued that North Carolina’s law, which prohibits people from using public restrooms that do not correspond with the gender listed on their birth certificates, compels “public agencies to follow a facially discriminatory policy.”

Even before the Justice Department challenged the law in court, the federal government had been examining how it could pressure North Carolina. Last month, federal agencies acknowledged that they were studying whether the law affected North Carolina’s eligibility for aid from Washington that helps pay for schools, highways and housing.