Citizens of all nationalities living in Scotland are to be given the vote in a move that will add around 55,000 people to the electoral roll.
The legislation published today by the Scottish Government would give Scotland one of the most liberal voting rights laws in the world.
The new voters would also be able to participate in a second independence referendum if one is called.
Currently, Commonwealth and Irish citizens can vote in all UK elections, while EU citizens can vote in local, devolved and European elections.
However, citizens of other countries are not able to vote regardless of how long they have been settled in the UK.
The Scottish Elections (Franchise and Representation) extends the right to vote in Scottish Parliament and local elections to all legal residents.
“Scotland has already led the way by lowering the voting age to 16, and we are building on this progress by extending the right to vote to everyone legally resident here,” parliamentary business minister Graeme Dey said.
“Extending voting rights to all citizens with a legal right to residency demonstrates Scotland’s commitment to equally value everyone who chooses to make our country their home, and is a demonstration of the kind of Scotland we are seeking to build.
“It is only fair that foreign nationals with the permanent right to live here, whether from EU countries or elsewhere, have the right to vote and stand as candidates in devolved elections.”
A consultation in 2018 found the move was supported by 78% of individuals and 92% of organisations that responded.
The legislation also gives the vote to prisoners serving sentences of less than 12 months.
It follows a ruling from the European Court of Human Rights that said a blanket ban on prisoner voting breached the European Convention of Human Rights.
Mr Dey added: “We have decided not to extend voting rights to all prisoners. We are confident that restricting prisoner voting to those serving sentences or less than 12 months means we can comply with the Court’s ruling.
“This measure will also support rehabilitation and reintegration back into society in order to reduce reoffending.”
Prisoners will be registered to vote at their ordinary or previous address in Scotland, and will only be registered to vote where they are serving their sentence as a last resort, the Scottish Government said.