The Scottish Government's public bodies bill will force NHS boards and local councils to work together to provide care and reduce delayed discharges.
The legislation will drive a long-standing commitment to integrate health and social care.
It follows concerns that hospitals have been left treating patients longer than necessary because care packages provided by local authorities were not in place by the time they were ready to be discharged.
Figures yesterday showed bed blocking was on the rise.
The bill was widely welcomed though concerns remained that reorganisation without extra resources would not address the problem.
Health Secretary Alex Neil said: "This is a landmark health and social care reform for Scotland.
"No-one wants to be in hospital longer than they should be.
"That is why I'm glad this Government has introduced legislation to integrate NHS and local authority budgets, which will help to reduce these delays."
Teresa Fyffe, director of Royal College of Nursing Scotland, said: "This bill should result in a huge shift in the way that health and social care are provided which, in turn, should significantly improve people's experience of health and social care services."
Dr John Gillies, chairman of Royal College of General Practice Scotland, said: "We are committed to ensuring general practice fulfils its critical role in successfully delivering the integration of health and social care in Scotland. Key to this success will be enabling a strong element of locality planning with input from clinicians, social workers and community groups. We look forward to helping take this forward."
Scottish Labour warned the bill would not end "conveyor belt care" for elderly people whose home carers were too busy to spend more than a few minutes with them for each visit.
Health spokesman Neil Findlay also said the bill should have ensured carers were paid the "living wage" of £7.45 per hour.
But Scottish LibDem health spokesman Jim Hume MSP said: "This legislation has been a long time coming. Liberal Democrats have consistently made the case for integrating health and social care as a means of alleviating pressure from our hospitals and giving people the support they need to be cared for at home."