WASHINGTON — The House passed sweeping legislation on Friday that would prohibit discrimination on the basis of sexual orientation and gender identity.

The bill, passed 236-173, comes as departments across the Trump administration have dismantled policies friendly to gay, bisexual and transgender individuals, like barring transgender recruits from serving in the military or formally rejecting complaints filed by transgender students who are barred from restrooms that match their gender identity.

“The question before us is not whether the L.G.B.T.Q. community faces outrageous and immoral discrimination, for the record shows that it clearly does,” said Representative Jerrold Nadler of New York, the chairman of the Judiciary Committee. “The question is whether we, as Congress, are willing to take action to do something about it. The answer goes straight to the heart of who we want to be as a country — and today, that answer must be a resounding ‘yes.’”

The legislation, which amends the Civil Rights Act of 1964, prohibits discrimination of lesbian, gay, bisexual and transgender people in both the public and private sectors, offering civil rights protections in businesses, hospitals and welfare services. It explicitly states that individuals cannot be denied access to a locker room or dressing room on the same basis.