OTTAWA -- Prime Minister Justin Trudeau apologized Tuesday on behalf of the federal government and all Canadians for decades of discrimination against members of the LGBTQ2 community.

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.

"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.

"These aren't distant practices of governments long forgotten. This happened systematically, in Canada, with a timeline more recent than any of us would like to admit."

The keenly anticipated expression of regret was accompanied by several initiatives to make amends to lesbian, gay, bisexual, transgender, queer and Indigenous people known as "two-spirit."

The government introduced legislation 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 fired as part of the so-called "gay purge."

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 projects that will "promote collective reconciliation and remembrance," including museum exhibits, a national monument and possible archival projects.

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

"The No. 1 job of any government is to keep its citizens safe. And on this, we have failed LGBTQ2 people, time and time again," Trudeau said in his remarks.

"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.

"I am sorry. We are sorry."

That was the point at when those in the galleries, who had sat quietly listening to the prime minister speak, began to applaud, before they were eventually joined on their feet by all MPs for a long-lasting ovation at the straightforward expression of regret.

The discriminatory policies that often ruined careers and lives had their roots in federal efforts that began as early as the 1940s to delve into the personal lives of people who were considered security risks as a result of what was considered "character weakness."

"This thinking was prejudiced and flawed," Trudeau said. "Sadly, what resulted was nothing short of a witch hunt.

"Those arrested and charged were purposefully and vindictively shamed. Their names appeared in newspapers in order to humiliate them, and their families. Lives were destroyed. And tragically, lives were lost."

After Trudeau was done, he was embraced one by one by a group of Liberal MPs who identify as gay or lesbian, including Randy Boissonnault, a special adviser to the prime minister on sexual orientation and gender issues.

Conservative Leader Andrew Scheer echoed Trudeau's sentiment.

"We are here today because many years ago and for too long the government of Canada failed in its duty to protect the basic rights of hundreds, thousands of the very Canadians who have dedicated their lives to public service," Scheer said, calling it "a terrible and unjust moment" in the history of the country.

Scheer, a social conservative who has voted against a transgender rights bill and refused to take part in gay pride parades, asserted that "all human beings have the same value and dignity, deserve the same respect."

Still, many Conservative MPs did not attend the apology.

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

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

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

Green party Leader Elizabeth May spoke passionately about those who were kicked out of the military and public service for who they are, noting that Canada experienced a loss of potential.

"Our stupidity, blindness and ignorance harmed our society while bringing real injustices and long-lasting pain on people who did nothing wrong and wanted to serve our country," said May.