OTTAWA — Discrimination against transgender people will be formally banned across Canada, and crimes against them will be included in the country’s hate crimes law, under new legislation introduced on Tuesday by the Liberal government of Prime Minister Justin Trudeau.

The legislation comes at a time of intense debate over transgender rights in the United States, and it fulfills a pledge Mr. Trudeau made during his election campaign last year. The government timed the introduction of the bill to coincide with an International Day Against Homophobia, Transphobia and Biphobia.

“Everyone deserves to live free of stigma, persecution and discrimination — no matter who they are or whom they love,” Mr. Trudeau said in a statement. “Today is about ensuring that all people — regardless of sexual orientation or gender identity — feel safe and secure and empowered to freely express themselves.”

Jody Wilson-Raybould, the justice minister, said the government had acted on recommendations from advocates for transgender people, and had written the legislation to cover both gender identity, or how people define themselves, and gender expression, or how people choose to act, dress or otherwise display their identity.