MSPs have unanimously voted through a law giving automatic pardons to gay men convicted under historical discriminatory legislation.

The Historical Sexual Offences (Pardons and Disregards) Bill automatically pardons gay men convicted under historical discriminatory laws.

It also allows them to apply for past convictions of this nature to be legally disregarded or removed from criminal records.

Private same-sex activity between two men aged over 21 was not legalised in Scotland until 1981 and the age of consent for gay men was reduced to 16 only in 2001.

The last anti-gay references remained on the criminal statute book in Scotland until late 2013.

Police Scotland have identified up to 1261 offences recorded against 994 people which fall within the scope of the Bill.

MSPs heard evidence from a man who was convicted in the early 1990s of kissing a man in the street who said his career had been hindered as he feared applying for jobs which required a disclosure check.

They voted through the new legislation by 119 votes to zero.

Justice Secretary Michael Matheson said the new law means people will no longer face discrimination for "unjust" convictions.

He added: "This Bill makes absolutely clear, through the pardon, that this Parliament acknowledges that those who were convicted of offences for engaging in same-sex sexual activity had done nothing wrong.

"By establishing a disregard process, it will also ensure that people can take steps to ensure that they do not continue to suffer discrimination as a result of such unjust convictions.

"Seen within the context of the apology offered by the First Minister and all of the political parties in this chamber, this is a proud day for this Parliament and a proud day for Scotland."

The bill won cross-party support across the Holyrood chamber.

Scottish Labour's justice spokesperson Daniel Johnson MSP said:"Hopefully those, who should never have been branded criminals in the first place, will now feel justice has been restored.

"But we cannot rest on our laurels - discrimination and inequality remain all too prevalent in society and we must continue to tackle them."

Conservative equalities spokeswoman Annie Wells said the "landmark" law is a further step to "true LGBTI equality" and gives men convicted under the historical laws "the opportunity to really move on with their lives".

She said: "Modern attitudes have changed and by supporting this Bill today we are setting in stone that the policies of the past were wrong and that Scotland is on its way to becoming a more just, fair and equal society."