The core prohibition is that a gosses (one in the dying process) retains full legal status as a living person, so that hastening his death in any way is treated as murder: Mishneh Torah, Murderer and the Preservation of Life 2:7 rules that one who kills a gosses is liable like any other murderer, and Shulchan Arukh, Yoreh De'ah 339:1 and Arukh HaShulchan, Yoreh De'ah 339:1 forbid even touching, moving, or closing the eyes of a dying person before the soul departs, stating that closing his eyes is considered shedding blood, and that even though his suffering is great and death would be a relief, nothing may be done to hasten it.
This extends to the Gemara's own formulation in Shabbat 151b, which compares the dying person to a flame that is gradually going out, so that the slightest touch that extinguishes it early makes one a murderer, and Torat HaAdam, The Gate of Malady likewise treats any act that shortens life as equivalent to the gravest transgressions, forbidden even for the sake of relief. Sefer Chasidim 723 gives the practical application that one must remove even an unrelated disturbance, such as nearby wood-chopping or salt on the tongue, that is preventing the soul from departing, rather than actively induce death.
The famous case of Rabbi Chanina ben Teradyon's death by fire in Avodah Zarah 18a, where a Roman soldier hastened his death to spare him prolonged agony, is treated by Responsa Benei Banim, Volume IV, Essays 6:12 as the classic textual crux for euthanasia: the author wrestles with why Rabbi Chanina himself refused to open his mouth to the fire yet consented to have the soldier hasten his death, and questions the basis for distinguishing what is forbidden to a Jew from what a gentile may do in such a case.
Responsa Benei Banim, Volume IV, Essays 6:2-3 frames the human difficulty directly, asking whether human conscience permits standing by a patient suffering unbearable agony and sacrificing him on the altar of the principle of the sanctity of life, while insisting that any boundary drawn must guard against the prohibition against murder being gradually eroded, so that a mercy-killing of the suffering does not become a killing for the convenience of those around him.
Talks of Yeshayahu Leibowitz on the Parasha, Vayeilech 11:55 further sharpens this by distinguishing euthanasia from cases where the Torah itself permits transgression to save life, noting that unlike those cases, the law itself provides no opening to permit euthanasia under any circumstance, and Steinsaltz on Shmuel II 1:10 reads the Amalekite's killing of the mortally wounded Saul at his own request as a biblical instance of what would be called a mercy-killing, performed because Saul could not survive his fall.
Modern poskim apply these sources to contemporary medical situations. Peninei Halakhah, Likkutim II 15:3 and Peninei Halakhah, Likkutim II 15:4 state that the value of human life is infinite and beyond human measure, so that no human being may decide to end another's life, and that even a patient whose body and mind no longer function in any useful way may not be killed, since only God determines who lives and who dies.
Rav Mordechai Eliyahu addresses the specific question of withholding or withdrawing artificial life-sustaining measures: in Shut HaRav HaRashi 31:51 he rules that if a patient will certainly die without the machines and the machines merely delay death briefly while causing suffering, connecting him to them is forbidden, but where there is even a slight chance of recovery to meaningful life, there is no basis to forbid resuscitative measures, and causing suffering merely to prolong life a little with no hope of cure is likewise forbidden while causing no additional suffering is permitted. In Shut HaRav HaRashi 31:49 and Shut HaRav HaRashi 42:17 he takes up the related practical question of a dying patient who could be kept alive longer by artificial means such as ventilation or dialysis but will die regardless, and in Shut HaRav HaRashi 42:48 he brings earlier sources, including the Gilyon Maharsha and the Shevut Yaakov as cited in the Pitchei Teshuvah, discussing a patient near death who might be helped or instead killed more quickly by a risky treatment.
Tzitz Eliezer (14:101) holds that relieving a patient's suffering through medical means does not conflict with halakhah when halakhah itself permits such relief for a significant need, since other prohibitions may similarly be set aside for the sake of a sick person, while Mishpat Kohen 144 holds that an impediment threatening a person's life should be removed to allow for a longer life, which is more valuable than the shorter life that would otherwise remain, though noting that the benefit of such prolongation is not always certain.
Other Tzitz Eliezer responsa sharpen the boundaries of permissible action regarding the dying: Tzitz Eliezer (17:72) forbids disconnecting a machine sustaining one patient with only a short-term survival chance in order to give it to a patient with a long-term chance, since doing so directly causes the first patient's death; Tzitz Eliezer (17:66) condemns any public sanctioning of bloodshed and treats removal of a heart or liver from a living body for transplant as actual killing; and Tzitz Eliezer (13:89) addresses a terminally ill patient with no medical prospect of recovery, weighing the prevention of continued severe suffering and a dignified death against the needless prolongation of a body connected to many tubes.
Broader principles that frame why halakhah resists hastening death even for mercy appear in Mishneh Torah, Sabbath 2:3 and Mishneh Torah, Foundations of the Torah 5:1, which derive from "he shall live by them, and not die by them" that the Torah's laws are meant for mercy and life rather than death, and in Sanhedrin 74a and Shulchan Arukh, Yoreh De'ah 157:1, which establish that one may transgress most prohibitions to preserve life but must give up his life rather than commit murder, bloodshed, idolatry, or forbidden relations — underscoring that taking a life, even one's own to end suffering, is cast among the few absolute prohibitions.
Related rulings on preserving and valuing life more generally round out the picture: Nedarim 40a teaches that failing to visit and care for the sick is tantamount to shedding blood, Shulchan Arukh, Choshen Mishpat 426 obligates one to save another's life when able, Mishneh Torah, Murderer and the Preservation of Life 2:8 and Mishneh Torah, Murderer and the Preservation of Life 1:9 discuss the distinct cases of killing a terefah or a rodef, and Pesachim 25, Mishneh Torah, Human Dispositions 4:1, Mishnah Berurah 329:9-11, and Melammed Lehoil Part II 69:1-2 treat related questions of healing, bodily care, rescue, and the law of the fetus endangering the mother, which inform but do not themselves resolve the euthanasia question.