Bill guaranteeing patients' rights in Scotland passed
Patients in Scotland must be treated within 12 weeks according to new laws unanimously agreed by MSPs.
The Patient Rights (Scotland) Bill also introduces a legal right for patients to complain about their treatment.
Health Secretary Nicola Sturgeon said the bill marked an "important milestone" in the history of the NHS.
However, the British Medical Association (BMA) has warned the new 12-week target could force doctors to rush patients into treatment.
The BMA said in a statement: "For every patient, there will be different and often unique needs and doctors are concerned that this new target, enshrined in law, will create an inflexible system that forces doctors to rush patients into treatment without consideration of the particular needs of the patient."
Ms Sturgeon dismissed the complaint and defended the plan during its final debate at Holyrood.
She said: "We have a bill that will make a difference to patients in Scotland - and that has always been the intention, certainly of the government, and I hope of everybody else in the chamber."
The bill - which was backed unanimously - also provides for a charter of patients' rights and responsibilities within six months of the legislation coming into force.
The maximum waiting time of 12 weeks will start when a patient's treatment has been agreed and will apply to both day care and in-patient procedures.
Ms Sturgeon added: "The passing of this bill marks an important milestone in the history of the NHS.
"The measures contained in it will reassure everyone that if they have concerns about care or services, they are exercising their legal rights in raising a complaint."
Labour's Dr Richard Simpson said he was previously critical of the bill but added: "As now amended, I do believe it makes a valuable contribution to an important journey which this parliament has been on since its inception.
"We have come a long way - the whole culture of the NHS in Scotland has changed and it will continue to change."
Tory MSP Mary Scanlon, whose party voted against the early version of the bill, added her support to the updated plan.
She said: "There is undoubtedly a need for a more open and accessible system of patient feedback and a need to handle patient concerns in a sensitive and supportive manner."
Liberal Democrat Ross Finnie said he supported plans for a charter, but added: "I still don't believe that a parliament worthy of the name needs to save a bill in order to create a charter. I think we ought to perhaps pause and reflect on that.
"However, we must move forward, life is too short, and there are elements in this bill, in particular in relation to that charter, which will set out very clearly and concisely what patients' rights are, what they can expect."