Spanish MPs voted on Thursday by a large majority to recognising the right to euthanasia under strict conditions, despite opposition from the Catholic Church and the right.
The government bill was adopted by a large majority with 198 votes in favour, 138 against and two abstentions after its first reading in the Congress of Deputies, the lower house of the Spanish parliament.
It will still have to be approved next year by the Senate.
The two parties in the governing coalition, the Socialist Party and left-wing populist party Podemos voted in favour, along with their Catalan pro-independence allies and the liberals of Ciudadanos.
The conservative opposition People's Party (Partido Popular or PP) and the far-right Vox party opposed it.
The draft law provides that a person suffering from a serious, disabling, or incurable disease may be helped to die if they so request in order to avoid intolerable suffering.
The request must be made in writing and repeated fifteen days later. It must be accepted successively by two doctors and then examined by a commission.
A right of "conscientious objection" is provided for health professionals who refuse to participate in euthanasia.
The cost of the procedure will be reimbursed by Social Security.
"As a society, we cannot remain impassive in the face of the intolerable suffering of some people," Health Minister Salvador Illa said. The text responded to "a very cross-cutting demand from the majority of Spanish society," she added.
The PP denounced the "haste" with which the vote was organised, believing that the government had wanted to avoid a "serious debate".
PP deputy José Ignacio Echániz said the law was "a defeat for everyone, a failure for our health system and our society".
"In the face of euthanasia and assisted suicide, we defend palliative care, deep pain treatment and palliative sedation," he added.
Following the vote, the Vox party announced that it would file an appeal with Spain's Constitutional Court.
Since coming to power in 2018, the socialist government had already tried twice in vain to get this reform passed.
Currently, assisted suicide and euthanasia are punishable by two to 10 years in prison, which can be reduced if the person is suffering from a serious illness and has asked to die.
The vote comes almost 23 years after the death of the Spaniard Ramon Sampedro, who became quadriplegic at the age of 25 and then spent 29 years claiming the right to die. Once the offence was statute-barred, one of his friends admitted in court that she had participated in his assisted suicide in 1998.
This case inspired the film 'Mar Adentro' by Alejandro Amenabar, which won an Oscar in 2005.