Portugal's parliament has voted to allow medically assisted dying in certain limited circumstances.
Medical professionals will be allowed to help people die if they are in extreme suffering as a result of an incurable disease or severe injury and they are unable to end their own lives.
The vote overturned a series of vetoes exercised by the country's conservative President Marcelo Rebelo de Sousa.
Deputies overwhelmingly voted in favour of the law.
Almost all members of the governing Socialist Party (PS) backed the legislation, as did three smaller left-of-centre parties and the Liberal Initiative (IL). Several members of the largest opposition party, the centre-right Social Democrats (PSD), also supported the bill.
Isabel Moreira, the Socialist Party politician who steered the bill through parliament, hailed the vote as a realisation of freedoms aspired to in Portugal's 1974 Revolution, which ushered in democracy.
Overturning a presidential veto, she said, was "something normal" in a democratic state - not least after a public debate on the subject that has lasted for over three years.
Most PSD members voted against the bill, as did the far-right Chega party, the third largest in parliament, and the Communist Party (PCP).
The Chega leader André Ventura, who like the PSD leadership had demanded a referendum on the subject of euthanasia, told parliament during the debate that he did not believe that the law would ever come into force.
Even if it does, he argued, "there will not be a single doctor in Portugal" prepared to act on its provisions, and any future right-leaning parliament would move to repeal it.
President de Sousa - who in vetoing the bill in April acknowledged that he saw no legal anomalies in it, unlike previous versions that he sent to the Constitutional Court - is obliged to sign it into law within eight days of receiving it, once it is published in the official gazette.
But the reform can be derailed in the meantime, or at least delayed, if one in 10 members of parliament formally ask the Constitutional Court to review the legislation.
Several PSD members of parliament have already declared their intention to do so.
Euthanasia is fully legal in three European countries: Belgium, Luxembourg and the Netherlands. But assisted death and passive euthanasia - of various types - are legal in many more European countries.