Short answer
Euthanasia, ending a patient's life on purpose, is haram by agreement, even if the patient asks for it. Stopping or not starting treatment that specialists judge futile, such as a ventilator that only prolongs dying, is different: many Hanafi and other scholars allow it, because treatment is not obligatory when it offers no real hope.
Active euthanasia and assisted suicide are haram as killing. Since the Hanafi school does not make treatment obligatory, withholding or withdrawing machines that specialists agree are futile is permissible according to many contemporary Hanafi muftis, while comfort care continues.
The four schools agree on this.
Explanation
Life belongs to Allah, and no one dies except by His permission at a set time. Ending a life on purpose, by injection or overdose, is killing, and the patient's consent does not change that, since a person may not take their own life either. The Prophet ﷺ told the sick not to wish for death because of harm that has befallen them, and to say instead, "O Allah, keep me alive while life is better for me, and take me when death is better for me." The four schools agree that euthanasia is forbidden.
Allowing death to come is different from causing it. The Hanafi texts say that a person who leaves treatment is not sinful, because a cure through it is not certain. On this basis many contemporary Hanafi muftis allow a family, with the doctors, to decline treatment that only prolongs dying, such as CPR in the final stage of a terminal illness, and to withdraw machines that specialists agree can no longer help.
Brain death is a point of difference. The OIC Islamic Fiqh Academy treats it as death, so machines may be switched off. Many South Asian Hanafi scholars hold that death takes place only when the heart and breathing stop. Even so, many of them allow futile life support to be withdrawn.
Pain relief and comfort care are good and should continue. Sit with your loved one, recite to them and help them say the shahadah. See what to say when someone dies. Every case is different, so ask a mufti with the medical team's assessment before deciding.
Ask a mufti about your own case. This answer explains the general ruling. When the details of your situation matter, as they do here, ask a qualified mufti and give them the full facts. Where to ask a scholar.
The evidence
Quran, Surah Aal-i-Imraan 3:145
وَمَا كَانَ لِنَفْسٍ أَن تَمُوتَ إِلَّا بِإِذْنِ ٱللَّهِ كِتَٰبًۭا مُّؤَجَّلًۭا ۗ وَمَن يُرِدْ ثَوَابَ ٱلدُّنْيَا نُؤْتِهِۦ مِنْهَا وَمَن يُرِدْ ثَوَابَ ٱلْءَاخِرَةِ نُؤْتِهِۦ مِنْهَا ۚ وَسَنَجْزِى ٱلشَّٰكِرِينَ ﴿١٤٥﴾
And it is not [possible] for one to die except by permission of Allah at a decree determined. And whoever desires the reward of this world - We will give him thereof; and whoever desires the reward of the Hereafter - We will give him thereof. And we will reward the grateful.
The time of death is Allah's decision.
Quran, Surah An-Nisaa 4:29
يَٰٓأَيُّهَا ٱلَّذِينَ ءَامَنُوا۟ لَا تَأْكُلُوٓا۟ أَمْوَٰلَكُم بَيْنَكُم بِٱلْبَٰطِلِ إِلَّآ أَن تَكُونَ تِجَٰرَةً عَن تَرَاضٍۢ مِّنكُمْ ۚ وَلَا تَقْتُلُوٓا۟ أَنفُسَكُمْ ۚ إِنَّ ٱللَّهَ كَانَ بِكُمْ رَحِيمًۭا ﴿٢٩﴾
O you who have believed, do not consume one another's wealth unjustly but only [in lawful] business by mutual consent. And do not kill yourselves [or one another]. Indeed, Allah is to you ever Merciful.
Taking a life, including one's own on request, is forbidden.
Sahih al-Bukhari 5671
Sahih... لا يتمنين أحدكم الموت من ضر أصابه ...
"None of you should wish for death because of harm that has befallen him."
Even wishing for death in suffering is discouraged, so causing it is far worse.
Sahih Muslim 2999
Sahih... عجبا لأمر المؤمن إن أمره كله خير ...
"How wonderful is the affair of the believer: all of it is good for him."
Patience in suffering is itself good for the believer.
Where the ruling is recorded
- al-Fatawa al-Hindiyya, Kitab al-Karahiyya, chapter on treatment. A person who leaves treatment and dies is not sinful, which is the basis for not continuing futile treatment.
- Resolutions of the Islamic Fiqh Academy (OIC), Resolution on resuscitation equipment. Brain death is treated as death, and life support may then be removed.
This answer is pending review by the scholars on our team. Quran translation by Sahih International. Hadith Arabic from the standard editions of the six books and the Muwatta, with gradings as recorded there; the English is our own rendering. Spotted a mistake? Tell us.