Prime Minister Justin Trudeau has delivered a long-awaited apology to members of Canada's LGBTQ community.

Hundreds of RCMP officers, members of the Armed Forces, and civil servants were targeted from the 1950s to the 1990s in what became known as the "Gay Purge."

They were harassed, attacked, or fired because of their sexual orientation.

Through his apology Trudeau said it is his hope that healing could now begin.

"Over our history our laws and policies led to much more than the legitimization of inequality, they legitimized hatred, violence, and brought shame to those targets," said Trudeau.

"While we may view Canada as a forward-thinking progressive nation we can't forget our past. The state orchestrated a culture of stigma and fear around LGBTQ communities and in doing so destroyed people's lives. Mr Speaker a purge that lasted decades will forever remain a tragic act of discrimination suffered by Canadian citizens at the hands of their own government."

Trudeau delivered the apology -- which surpassed what other countries have done to make amends to LGBTQ people -- in the House of Commons following question period Tuesday.

"It is with shame and sorrow and deep regret of the things we have done that I stand here today and say we were wrong, we apologize. I am sorry. We are sorry," said Trudeau.

CTV Montreal first reported earlier this year that the Canadian government was going to apologize to members of the Canadian Armed Forces who were harassed and pushed out of jobs because of their sexual orientation.

A clear and unequivocal expression of regret to all affected was necessary to acknowledge the mistakes so "they will never happen again," said Liberal MP Randy Boissonnault, a special adviser to the prime minister on sexual orientation and gender issues.

The apology and associated efforts to recognize past wrongs are genuinely historic, said Gary Kinsman, a sociology professor at Laurentian University and a leading scholar on the injustices for many years.

"It's also been an incredibly long time coming," said Kinsman, a spokesman for the We Demand an Apology Network, which includes people directly affected by the purge campaign as well as supporters and researchers.

"I'm very saddened by the fact that many of the people who really needed to be apologized to have passed away," Kinsman said. "It should have happened decades ago, in my view."

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.

There is no evidence of a gay or lesbian employee ever giving information to Soviet agents or another foreign power, Kinsman said. On the contrary, victims of the purge say the only ones who tried to blackmail them were the RCMP or military security, trying to elicit information about friends and acquaintances in the public service.

"Really what it was about was pushing lesbians and gay men outside the fabric of the nation, defining our sexualities as being somehow a security risk," Kinsman said. "And on the other side, defining heterosexuality as the national safe and secure sexuality."

he apology included a federal commitment to reveal more of the hidden historical record of the government's discriminatory policies and practices.

The government also tabled legislation Tuesday to expunge the criminal records of people convicted of consensual sexual activity with same-sex partners, whether in civilian or military courts.

Those eligible will be required to apply for expungement; requests may be submitted on behalf of deceased people who were convicted.

Among apology-related initiatives, the government is putting $250,000 toward community projects to combat homophobia and provide support for people in crisis.

In addition, it plans a commemoration in 2019 of the 50th anniversary of the federal decriminalization of homosexual acts.

Meanwhile the Trudeau government has earmarked more than $100 million to compensate members of the military and other federal agencies whose careers were sidelined or ended due to their sexual orientation, The Canadian Press has learned.

The money will be paid out as part of a class-action lawsuit settlement to employees who were investigated, sanctioned and sometimes fired as part of the so-called "gay purge."

An agreement in principle in the court action emerged Friday, just days before the government delivered a sweeping apology for discrimination against members of the LGBTQ community.

Details of the agreement must still be worked out by the parties and approved by the Federal Court, but it's expected that several thousand people will be eligible for the financial compensation.