Portugal's parliament has passed a law allowing medically assisted dying, putting the Catholic-majority country on course to become the fourth in Europe to legalise euthanasia.
Before coming into force the bill must first be signed into law by President Marcelo Rebelo de Sousa, a staunch Catholic and conservative who was re-elected only last weekend.
However, the president - who has yet to make public his position on the issue - could also either use his veto against the legislation, or refer it to the country's constitutional court for further study.
The bill was adopted in parliament by 136 votes to 78 with four abstentions - thanks largely to a majority of votes from the ruling Socialist Party which had allowed its MPs to vote freely.
If the president did decide to veto, a second vote by lawmakers would override it.
Politicians had approved proposals aimed at changing the law in February, setting up the vote despite a campaign by the Church for a national referendum on the issue.
Socialist MP Isabel Moreira, a constitutional law expert who helped draft the law, said that it would respect "free choice and every individual's independence".
The bill legalises access to assisted suicide for adult patients in a situation of "extreme suffering and irreversible damage".
Several doctors must green-light the procedure, while a psychiatrist would be called in if there are doubts about the patient's ability to make a "free and informed" choice.
Euthanasia is legal in three European countries - Belgium, The Netherlands and Luxembourg - while others allow terminally ill people to refuse life-maintaining treatment or to have help to die.
"People deserve the right to be able to choose," retired oncologist Jorge Espirito Santo, who has campaigned for years to make euthanasia legal in Portugal, said before the vote.
He said he was expecting a "historic day".
The Catholic Church, which predominates in Portugal, campaigned against the bill both among its own faithful and those of other denominations.
Its bishops' conference immediately expressed outrage at parliament's approval of the legislation, calling the law an "unprecedented step backwards".
In December, parliament in neighbouring Spain voted by a wide margin to approve a bill that will allow euthanasia under strict conditions, despite fierce opposition from the Catholic church and conservative parties.