Gay men across Scotland who were prosecuted for having sex under old laws will be pardoned in a new bill.

The bill will allow thousands of gay and bi men to get previous convictions removed from their record.

Thousands were prosecuted under Scotland’s anti-gay law, which remained on the statue book until 1981.

Scotland didn’t decriminalise homosexuality until 14 years after England and Wales in 1967.

Scotland’s first minister, Nicola Sturgeon, offered an apology to all of the gay and bisexual men who were convicted under the law.

“Within the lifetime of this parliament, this nation’s laws created suffering and perpetrated injustice,” Sturgeon told MSPs.

“The legislation we have published today addresses this injustice.”

Sturgeon added: “Until we live in a world where no young person faces hate, fear and prejudice simply because of their sexual orientation or gender identity, we still have work to do.”

She also promised LGBT+ people that her government are “utterly committed” to fighting for full equality.

Gay men still living with these convictions watched as Sturgeon made the announcement in Holyrood, and were visibly emotional from the gallery.

Back in January of this year, the UK Home Office awarded thousands of pardons to the deceased men who were convicted as a result of having sex with the same sex across England and Wales.

However, 15,000 of the 65,000 men who were convicted are still living with a record for breaking the old law.

If these men want a clean record, they would have to apply to have their convictions deleted, whereas in this new bill in Scotland, the pardon will be automatic.

Stonewall UK have called upon UK ministers to follow the Scottish government’s lead on this.

“The disregard scheme in England and Wales doesn’t cover all the offences it should, but we secured a commitment from the UK government to change this,” said Stonewall’s Calum Macfarlane.

“We are now working with the Home Office to ensure that everyone who should have their crime disregarded can do so. And we will be working with the Scottish government to achieve the same result for people in Scotland.”

While homosexuality remained illegal in England and Wales until 1967 and in Scotland until 1981, it wasn’t until 1994 that the age of consent for gay men was lowered from 21 to 18.

That still wasn’t in line with the heterosexual age of consent of 16, and gay and bisexual men had to wait until 2001 for full equality on that front.

Related: “I don’t want to die with a criminal record,” says gay German pensioner as country wipes out historic convictions