The Cost of Living (Tenant Protection) (Scotland) Bill gives ministers temporary powers to cap rents for private and social tenants.
Evictions will only be allowed under certain circumstances.
Tenants' Rights Minister Patrick Harvie said it would support tenants through the current cost of living crisis.
The legislation, which was fast-tracked through the Scottish parliament's scrutiny process, can be extended over two further six-month periods.
The Scottish Conservatives had previously voiced their opposition to the move, as the legislation was only introduced and published on Monday evening.
A Holyrood committee had heard some rents had soared by as much as 30% but landlord representatives said the government's plans would force many of its members to quit the sector.
The Scottish Federation of Housing Associations said a rent freeze in the social housing sector was unnecessary, likely to be counterproductive and should not continue beyond the end of March next year.
There are exceptions to the rent freeze where a landlord faces increased property costs, mortgage interest payments and some insurance costs.
Approved amendments included changes to the details needed from landlords to provide evidence of financial hardship, including letters from money advisers or accountants.
The legislation, which was approved by 89 votes to 27, also covers student accommodation and provides for a six-month moratorium on evictions.
It will be the first bill passed by Holyrood to be given Royal Assent by King Charles III.