MSPs have voted to tighten the law on off-sales and devolve the decision on pub opening hours to local licensing boards amid chaotic scenes.
The prospect of 24-hour opening caused political controversy
The debate on the Licensing (Scotland) Bill began with confusion over the number of last-minute amendments.
The bill allows the sale of alcohol in pubs and clubs 24-hours a day, but only in exceptional circumstances.
During a heated and ill-tempered debate at Holyrood, MSPs backed the bill by 71 votes to 42 with four abstentions.
Licensing inspectors will be appointed and landlords who sell alcohol to under-18s will face custodial sentences.
An amendment by Labour MSP Frank McAveety restricting off-sales opening from 1000 GMT to 2200 GMT was agreed by 92 votes to 27, with no abstentions.
There was a flurry of late amendments to the bill and proceedings were halted briefly amid confusion over whether MSPs had the correct paperwork.
The move sparked anger among opposition politicians who accused the Scottish Executive of panicking.
The new law gives local licensing boards the power to decide the opening hours of pubs and clubs, though 24-hour opening will only be allowed in exceptional circumstances.
A Lib Dem amendment to give licensing boards more control over opening hours for off-sales was defeated.
Mr McAveety's amendment will see off-sales opening times changed from the current 0800 GMT to 2200 GMT on Monday to Saturday.
The MSP said he believed his proposal struck the right balance and reflected the need to ensure stronger licensing legislation.
"Critically and importantly, we need to try and ensure that we don't make it easier for loopholes to be found for individuals to maximise that," Mr McAveety added.
Deputy Presiding Officer Murray Tosh suspended proceedings for a period due to the number of last-minute amendments to the bill.
SNP MSP Bruce Crawford said: "I really cannot understand why the Scottish Executive has allowed itself to get into this situation at this late juncture.
"It is chaos. Frankly for the people outside it must look like panic and it can only be embarrassing. It has been a bourach."
Socialist MSP Tommy Sheridan described the situation as one of the most shambolic since devolution, adding: "This is supposed to be a serious legislative chamber".
Labour and Lib Dem ministers had split over moves to give licensing boards control over off-sales opening times.
Overall, Labour, the Liberal Democrats and the Greens backed the bill while the SNP and Conservatives opposed it.