"Today we are a more human, fairer and freer country," said Prime Minister Pedro Sanchez after Spanish lawmakers approved the euthanasia bill on Thursday.
Spain became on Thursday the fifth country in Europe to legalise assisted suicide and euthanasia for long-suffering patients of incurable diseases and people with unbearable permanent conditions.
The Spanish parliament's lower house voted 202-140 with two abstentions on the final passage of the euthanasia bill.
MPs from Spain's left-wing governing coalition and other parties supported it, while conservative and far-right lawmakers voted against the legislation, vowing to overturn it in the future.
"Today we are a more human, fairer and freer country," Prime Minister Pedro Sanchez tweeted on Thursday.
"Thank you to all those who fought tirelessly for the recognition of the right to die with dignity in Spain."
The adoption of the bill marked the culmination of a long legislative journey that began three years ago and underwent several rounds of revision in parliamentary committees and in the Senate.
The law is expected to enter into force in mid-June. It comes after several emblematic cases in the country struck a deep chord in public opinion.
One of them was that of Ramon Sampedro, a quadriplegic man played by Javier Bardem in the Oscar-winning film "Mar adentro".
It is a victory "for the people who will be able to benefit from it" and also "for Ramon", said Ramona Maneiro, the friend of Sampedro who helped him to die in 1998.
The Spanish Catholic Church has vehemently condemned the reform, comparing euthanasia to "a form of homicide".
Far-right Vox party said it would launch an appeal to the Constitutional Court.
About a hundred people protested against the legislation outside Parliament on Thursday, with some disguised as grim reapers and deploying a banner against the "government of death" to the sound of funeral drums.
This law "violates the right to life, without which no other exists," said protester Alexander Cuevas, 21.
The conditions for Spain's public health system to provide life-ending assistance will be strict under the new legislation.
The person -- a Spanish citizen or resident in the country -- must be "capable and conscious" when making the request, which has to be formulated "without external pressure" and renewed fifteen days later.
Doctors may reject the request if they deem the criteria are not met. They may also use a "conscientious objection" motive to refuse to perform the act.
In addition, the decision must be approved by another doctor and receive the green light from an evaluation committee.
A global debate
Euthanasia — when a doctor directly administers fatal drugs to a patient — is legal in Belgium, Canada, Colombia, Luxembourg, the Netherlands and Switzerland.
In some US states, medically assisted suicide — when patients self-administer lethal drugs under medical supervision — is permitted.
Portugal tried to pass a law similar to neighbouring Spain in January.
But the country's Constitutional Court this week blocked the legislation, arguing it was too imprecise.