OTTAWA — Prime Minister Justin Trudeau began by telling a story — one that began not that long ago and, in some ways, is still unfolding — about how the federal government spent decades ruining the careers and lives of Canadians because of their sexual orientation or gender identity.

“This is the devastating story of people who were branded criminals by the government — people who lost their livelihoods, and in some cases, their lives,” Trudeau said Tuesday as he delivered a speech building up to his promised apology for past state-sanctioned discrimination against members of the LGBTQ2 community in Canada.

“These aren’t distant practices of governments long forgotten,” he said.

“This happened systematically, in Canada, with a timeline more recent than any of us would like to admit.”

Dozens of people — including two of Trudeau’s own children, Xavier and Ella-Grace — crammed into the various House of Commons galleries to witness the historic occasion, which the prime minister said he hopes will finally allow the healing process to begin for those affected.

The expression of regret, and the emotional reaction to its delivery, built like a crescendo as Trudeau walked through the ways the federal government caused harm to lesbian, gay, bisexual, transgender, queer and two-spirited people, a term used broadly to describe Indigenous Peoples who identify as part of the community.

That included the criminalization of homosexual sexual activity, raids on bathhouses, public humiliation and efforts to rid the military and the public service of LGBTQ people, until as recently as 1992.

Then, Trudeau began to move on from the lesson in history to the abject apology for it having happened in the first place.

“It is with shame and sorrow and deep regret for the things we have done that I stand here today and say: We were wrong. We apologize,” he said.

“I am sorry. We are sorry.”

That was the point when one man in the gallery, where some had been quietly wiping tears from their eyes, began clapping his hands.

Others, many wearing name badges and rainbow ribbons, began to join in, until all the MPs on the floor of the House of Commons were on their feet for the straightforward expression of regret.

Liberal MP Rob Oliphant, who sat beside Trudeau throughout the apology, said that was a key moment for him.

“There was no equivocation. There was no justification,” said Oliphant, who said he felt many of the experiences of his life as a gay man, from playground taunts to lost job opportunities, flash before his eyes as the prime minister spoke.

“There was no, ‘Well, we didn’t know things that we know now,”‘ he said. “There was none of that.”

The apology was accompanied by several initiatives to make amends.

The Liberal government introduced legislation Tuesday which, if passed, will allow the expungement of criminal records for people convicted of consensual sexual activity with same-sex partners.

The government has also earmarked $110 million to compensate members of the military and other federal agencies whose careers were sidelined or ended due to their sexual orientation, the centrepiece of a class-action settlement with employees who were investigated, sanctioned and sometimes forced out of their jobs.

As part of the settlement, the government will also pay an additional $20 million for legal fees and administration and devote at least $15 million more for memorial activities, including museum exhibits, a national monument and possible archival projects.

Separately, the government is putting $250,000 toward community projects to combat homophobia and provide support for people in crisis, and in 2019 plans to commemorate the 50th anniversary of the federal decriminalization of homosexual acts.

After recounting the horrors of the past, and acknowledging there is still work to do, Trudeau sounded a hopeful note for the future.

“To the kids who are listening at home and who fear rejection because of their sexual orientation or their gender identity and expression, and to those who are nervous and scared, but also excited at what their future might hold: we are all worthy of love, and deserving of respect,” he said.

After Trudeau was done, he was embraced one by one by Liberal MPs who identify as gay or lesbian, including Randy Boissonnault, his special adviser on sexual orientation and gender issues.

“In this country, we deplore and we condemn injustice towards the innocent, the oppressed and the persecuted,” said Scheer, who urged everyone to stand up for human rights both at home and abroad, where many countries still criminalize homosexual activity.

“Canada is better than that. We must do more to stand up for the LGBTQ2 community in places like Iran and Russia and other countries where they are the target of brutal violence,” said Scheer, who then praised the work of the previous Conservative government in prioritizing these refugee groups.

Scheer, who has voted against the transgender rights bill and refused to take part in gay pride parades, leads a Conservative caucus where many share those social conservative views. There were many Conservative MPs who did not attend the apology.

Guy Caron, the parliamentary leader for the NDP, said he welcomed the apology and said his party would work with the Liberals to make sure the expungements legislation is passed quickly.

Still, like Trudeau, he noted how much work there is to do to end all discrimination against the LGBTQ community, including ongoing restrictions on sexually active gay men who wish to donate blood.

“This would be a good time to stop doing things the government might have to apologize for in the future,” said Caron.

Todd Ross, a former naval officer who is involved in the class-action lawsuit, said he was filled with so much emotion listening to the apology from the gallery that he feels like he needs to go back and read the words again in order for them to sink in.

“It was something I needed to hear,” said Ross.

“I think it marks the beginning of healing for many people,” he said. “I accept the apology.”