The Opposition private member's legislation passed by a vote of 149-137, with the crucial support of 18 Conservatives, including four cabinet ministers.
It was one of the first tests of the Conservative caucus' resolve on lesbian/gay/bisexual/transgender (LGBT) rights in Canada at a time when Foreign Affairs Minister John Baird has been mounting a strong defence of such rights abroad.
Baird, Finance Minister Jim Flaherty, Labour Minister Lisa Raitt and Heritage Minister James Moore were among the Conservatives who supported the bill. Prime Minister Stephen Harper, most of his front bench and the vast majority of his backbenchers opposed it.
Opposition parties were united in their support for the bill, sponsored by New Democrat Randall Garrison.
MPs are generally free to vote as they see fit on private members' bills.
"Today, New Democrats are proud to have contributed to ensuring equal protection under the law from discrimination and hatred based on gender identity," Garrison said in a statement after the vote.
"Transgender and transsexual citizens are among the most marginalized and are too often victims of harassment and acts of violence."
The bill had triggered vigorous, sometimes emotional debate in the Commons.
After passing at second reading last year — with the support of 15 Tories and another nine abstaining — the bill's momentum seemed to falter as some Conservatives began to express reservations about its impact and effectiveness.
There were complaints that the language in the bill was confusing and vague, including the term "gender expression" and "gender identity."
Garrison tried to strike a compromise by removing the term "gender expression."
Conservative MP Michelle Rempel teared up in the Commons earlier this month as she spoke about the discrimination that transgender Canadians face, even as she questioned the bill's effectiveness.
"Both sides of this debate should agree that equality and protection against harm are two fundamental values that all Canadians of any gender, any age, any background are entitled to," Rempel said.
"However, as legislators we are also tasked with deciding if the proposed legislation is sound. Given the lack of clarity that I found in the bill, I do have concern about its viability."
Other Conservative MPs opposed the bill on other grounds, such as the argument that pedophiles would be protected when they lurked in public bathrooms.
Shortly before the vote, Calgary MP Rob Anders tabled a petition "on behalf of thousands" of Canadians opposed to what he called "the bathroom bill."
"These constituents feel that it is the duty of the House of Commons to protect and safeguard our children from any exposure and harm that would come from giving a man access to women's public washroom facilities," Anders said.
The Canadian Human Rights Tribunal had supported adding transgender identity to federal anti-discrimination and anti-hate legislation, saying it would promote acceptance and send a message about tolerance.
While some MPs argued that the transgendered were already protected on the basis of sex and disability, the tribunal said it would be better to have explicit protection so that the question is not perpetually challenged.
Note to readers: This is a corrected story. An earlier version said 16 Conservatives had supported the bill.
Also on HuffPost