MSPs have approved Scottish government plans to end short jail terms as part of wide-ranging justice reforms.
The government's Criminal Justice and Licensing Bill, passed by parliament, includes a presumption against prison sentences of three months or less.
Ministers said the move, along with tougher community sentences, would reduce reoffending.
Labour said the move would fail to tackle domestic violence, where offenders often got short jail terms.
The bill was passed by 64 votes to 61.
The government originally set out a presumption against prison terms of six months or less, but was forced to water down the plans to gain enough opposition support.
As MSPs debated the bill in parliament at its final stage, Justice Secretary Kenny MacAskill said Scotland did have a domestic violence problem, but insisted prison was not always the answer.
Ministers also moved to strike from the bill a Labour-backed measure to jail people who carry knives for six months.
The Scottish government wants to reduce reoffending by greater use of tough, non-custodial sentences, known as community payback orders.
Mr MacAskill said cutting short jail terms, also opposed by the Scottish Tories, would make communities safer and "end the free bed-and-board culture."
And he told MSPs: "Do we have a problem in Scotland with domestic violence? Yes we do. Is it all solved by prison sentences? No I don't think so.
"Do those who commit serious violent offences deserve to go to prison? Absolutely. Is that where they'll go? Definitely."
Referring to Scotland's "machismo" culture, the justice secretary added: "The rhetoric that comes from the Labour-Tory coalition seems to be that the way we're going to sort it out is we're going to ramp up, tool up and get tore in."
The minister also said sheriffs could still jail people for less than three months, if the reasons were strong enough to override the "presumption".
Labour justice spokesman Richard Baker said the presumption against short sentences was unfunded, would put too much extra pressure on community sentence bosses, and would take in serious offences like assault and knife crime.
He added: "Of those who receive custodial sentences for domestic abuse, some 68% receive a sentence of three months or less.
"And that window of opportunity, which might be a month or two months, can be crucial in those situations."
Tory justice spokesman John Lamont said short-term custodial sentences would "always be a necessary part of our summary justice system", even though UK Justice Secretary Ken Clarke has called for fewer short sentences.
"If an individual is a persistent offender or continuously breaches their community sentencing orders, then the judiciary may feel a short prison sentence is the best disposal to fit the circumstances," said Mr Lamont.
The Lib Dems' Robert Brown, who backed the three-month presumption, said his party supported the ability to increase the presumption to six months in future, adding: "Short-term sentences don't work in the vast majority of cases. That's the reality of the position."
And Green MSP Patrick Harvie, who withdrew a bid to restore the government's original six-month threshold to the bill, said: "Prison is good at one thing. It's got walls, it's good at confinement. That's all it's good at.
"Even many of those people who work very hard to try and provide the rehabilitation services . . . will admit privately that they're fighting a losing battle inside the walls of prisons."
The Criminal Justice and Licensing Bill also brings in a number of new criminal offences, including specific action to tackle organised crime, stalking, people forced into "slavery or servitude" and possession of "extreme pornography".
New measures also aim to clamp down on the use of mobile phones in prison.
And the bill will create a new sentencing council to provide guidance to the courts on disposing of criminal cases.
The age at which a child can be prosecuted in an adult court will rise from eight to 12 and the remand of children in adult prisons will end.
MSPs rejected an amendment brought forward by SNP backbencher Sandra White MSP on greater restrictions for lap dancing clubs.