EDINBURGH — Scotland's devolved government issued an apology on Tuesday to men convicted in the past for same-sex activity and passed a new law which will allow them to clear their names.

"It is only right that we address this historic wrong," First Minister Nicola Sturgeon told the Scottish parliament.

First Minister Nicola Sturgeon, makes a formal apology to gay men at the Scottish Parliament on November 7, 2017 in Edinburgh, Scotland. Jeff J Mitchell / Getty Images

"Discriminatory laws, although abolished, continue to have implications for people to this day," she added. "The wrong has been committed by the state to them, not by the individuals."

The Morning Rundown Get a head start on the morning's top stories. This site is protected by recaptcha

She added: "I categorically, unequivocally and wholeheartedly apologize for those laws and for the hurt and the harm they did to so many."

Watching from the gallery, same-sex couples wept, held hands and applauded.

Consensual homosexual acts between men aged over 21 in Scotland were decriminalized in 1981.

"(The) apology will give a great deal of comfort to many who were unjustly prosecuted and will help draw a line, once and for all, under a dark period in Scotland's history," gay rights group Stonewall said in a statement.

The legislation "acknowledges the wrongfulness and discriminatory effect of past convictions for certain historical sexual offences" by pardoning people convicted of those offences and providing a legal process for convictions to be disregarded.

In January, the UK government passed a similar law relating to England and Wales.

FOLLOW NBC OUT ON TWITTER, FACEBOOK AND INSTAGRAM