All parties, apart from Holyrood's 16 Conservative MSPs, voted for the Housing (Scotland) Bill last night in a move that will also see the end of the right to buy for all new homes built in the social sector.
Conservative attempt to introduce blocking amendments failed as SNP, Labour and Liberal Democrats voted them down.
The bill's passage was hailed as a "historic day for social housing" by Alex Neil, the housing minister. The Scottish Government believes the changes mean up to 18,000 fewer homes will be sold off over the next decade, helping boost the stock of affordable homes for rent.
Under the new law, an independent Scottish Housing Regulator will be established with the aim of safeguarding and promoting the interests of current and future tenants, as well as homeless people.
About one in four households in Scotland live in either a council or housing association home.
Mr Neil said: "This is a truly historic day for social housing in Scotland. By passing the housing bill, the Scottish Parliament has ensured social housing is protected for future generations - providing homes for the people and jobs in the Scottish economy."
Mr Neil earlier told MSPs the legislation demonstrated his government's "willingness to seek radical solutions to the problems of inadequate supply and poor quality in housing".
He said it would introduce "important measures that will safeguard social housing for future generations", adding that the SNP administration had provided 80 million for council housebuilding, with this funding nearly 3,500 new homes across Scotland.
He added: "Councils have been willing to start building again because they know those houses will continue to be available as affordable houses to rent for future generations."
?Mr Neil's SNP colleague Bob Doris said: "Today's bill restores the ability of councils to invest in housing for the long term and ends the destruction of council housing begun by Mrs Thatcher's right to buy."
But the Conservatives were furious arguing that political dogma had accounted for a right-to-buy policy that was the biggest driver for social change in Scotland in the last 50 years.
Scottish Tory MSP David McLetchie said: "The establishment of the right-to-buy has enabled 450,000 households to own their own home.
"Home ownership remains the clear aspiration for the vast majority of Scots and it is wrong to deny them this through a political dogma.
"Ending the right-to-buy of new tenants will not increase the stock of affordable housing.It will only serve to deny councils and registered social landlords the benefit of sale receipts which could be reinvested in new housing programmes at a time when their housing budgets are likely to be cut.
"The other parties have indulged in gesture politics rather than delivered real solutions to Scotland's housing needs."
Graeme Brown, the director of housing charity Shelter Scotland, praised the Scottish Parliament for its "courage and strength in seeing this bill through".