Self-sacrifice in Jewish law
Although rare, there are instances within Jewish law that mandate a Jew to sacrifice their own life rather than violate a religious prohibition. One  of these prohibitions is that no life should be taken, including one's own. Many more ritual prohibitions exist as well, which means that under limited circumstances a Jew has to self-sacrifice when the greater good calls for breaking a more minor dictate. This practice reflects the practical and perhaps malleable nature of Judaic law. Overview
In general, a Jew must violate biblically mandated, and certainly rabbinically mandated, religious laws of Judaism in order to preserve human life. This principle is known as ya'avor v'al ye'hareg (, "transgress and do not be killed") and it applies to virtually all of Jewish ritual law, including the best known laws of Shabbat and kashrut, and even to the severest prohibitions, such as those relating to circumcision, chametz on Passover, and fasting on Yom Kippur. Thus, the Torah generally asserts that pikuach nefesh (פיקוח נפש, "the preservation of human life") is paramount, and in most situations even the preservation of a limb is equated with the basic principle. This stems in part from the biblical injunction that the Judaic laws are given "that you shall live by them", a commandment traditionally interpreted as meaning "...and not die by them" - human life is generally considered more significant than keeping religious precepts at the risk of life (or in some cases risk of serious harm); however, three areas of prohibition may not be trespassed under any circumstances, even to save a human life: acts involving murder, some kinds of sexual misconduct, and idol worship. These areas are central to society and humanity, in the perspective of the Jewish religion, and their breach is of such magnitude that even under threat of being killed, one should refuse. These are sometimes informally referred to as the "three cardinal sins"; however, they actually encompass many more than a mere three prohibitions. The governing principle here is ye'hareg v'al ya'avor (, or "be killed but do not transgress"). Someone who runs great risks or accepts great hardship for the sake of observing the religious laws of Judaism without actually sacrificing his or her life is considered especially righteous. An act of such figurative self-sacrifice and acceptance of the possible consequence is called mesirat nefesh (, "giving over the soul"). Preservation of life in Judaism
Judaism places a high value on life. It is therefore permitted to disregard all but three domains of Judaism's 613 mitzvot (religious requirements) when a life is in danger. This rule is founded on the Biblical statement, "You shall keep my decrees and my laws that a person will do and live by them, I am God." () The Rabbis deduced from this verse that one should not die rather than transgress the mitzvot. This verse is the source of the doctrine that one should not endanger one's life to keep a mitzvah. Additionally,  states, "You shall not stand by the blood of your fellow." The Talmud derives from this verse that one must do everything in one's power to save the life of another Jew, even if this involves violating one or more of the mitzvot. If the life of a non-Jew or an apostate Jew is in danger, the law is not so clear and is the matter of some debate, but it is certainly within the spirit of the law, if not the letter. This also touches on Judaism's views regarding other religions; see Jewish views of religious pluralism. The requirement of self-sacrifice
Yehareg ve'al ya'avor ("Let him be killed rather than transgress") refers to the requirement to give one's life rather than transgress a law. Although ordinarily one is permitted to transgress halakha when a life is in danger, certain situations require one to give one's life. Three exceptional sins 
There are three sins for which one is always required to die rather than transgress:

 idolatry
 sexual misconduct such as incest, adultery, homosexuality, or bestiality (see sexual immorality prohibited by Torah)
 murder

The above three are ruled as being exceptions by the Talmud. In tractate Sanhedrin 74a, the Talmud records: "Rav Yochanan said in the name of Rav Shimon ben Yehotzadak: 'It was decided by a vote in the loft of the house of Nitezeh in Lod: For all the sins in the Torah, if a person is told, "Transgress and you will not be killed," they should transgress and not be killed, except for idol worship, sexual relations and bloodshed.'" A Jew must sacrifice his or her life rather than transgress the above-mentioned sins. Idolatry
The first exception, idolatry, is extrapolated from Deuteronomy 6:5 "And thou shalt love the Lord thy God with all thy heart, and with all thy soul, and with all thy might," meaning that one should even surrender one's life rather than serve any divinity aside from God. A famous example can be found in the Babylonian Talmud Gittin 57b, the apocryphal II Maccabees 7, and other sources about Hannah and her seven sons, a story associated with the holiday of Hanukkah. Rather than eat pork, Hannah defies King Antiochus IV and allows her sons to be killed one by one before she herself dies. This story, however, relates another exception where Halakha requires that one surrender one's life: a situation in which a person is forced to break a law for the sake of desecrating the Torah. If a non-Jewish ruler demands that a Jew cook food for him on the Sabbath, the Jew is required to desecrate the Sabbath rather than let himself be killed; however, if the ruler demands the Jew cook food on the Sabbath, not for the ruler's benefit but simply for the sake of dishonoring the Torah, then one is required to surrender one's life to avoid desecrating God's name (akin to idolatry). Hannah and her sons acted in this way when it came to eating pork for the sake of desecrating the Torah; by allowing themselves to be killed, they sanctified God's name in public. Sexual immorality
The exception for certain types of sexual immorality is extrapolated from Deuteronomy 22:26. Referring to the case of a betrothed girl who is raped by a man, it says, "for as when a man rises against his neighbor, and slays him, even so is this matter." Thus sexual immorality is likened by the Torah to murder – and one is required to give one's life rather than commit murder, as discussed below. Types of sexual misconduct involved
In both Orthodox Judaism and Conservative Judaism, the types of sexual misconduct subject to Yehareg v'al ya'avor include those mentioned in Leviticus Chapter 18, which include adultery with a married woman, various types of incest, sexual relations with a woman in the Niddah state, bestiality, and penile-anal sex between men (violations of the prohibition "thou shall not lie with a man as with a woman, it is an abomination" as agreed on by many Orthodox and some Conservative Jewish authorities). Prohibitions by Rabbinic decree are excluded. The Rabbis made a number of prohibitions in sexual matters beyond those of the Torah. Adultery with a married man, fornication, certain types of homosexual conduct (Orthodox authorities and traditionalists within Conservative Judaism consider a broader range of male-male sexual intimacy, including oral sex between men, as forbidden, but not included in the "die rather than transgress" prohibitions), and various aspects of modesty in dress and conduct are among these rabbinic prohibitions not specifically prohibited by Leviticus 18. Although Maimonides regards lesbian conduct as biblically prohibited on the basis of Sifra on Leviticus 18:3, he does not consider it sexual intercourse proper. Orthodox Judaism recognizes rabbinic prohibitions as being a lesser type of transgression overridden by the imperative to preserve life. In 2006 the Conservative movement's Committee on Jewish Law and Standards, reflecting strong disagreement between liberals and traditionalists on the subject, approved two diametrically opposed responsa on the subject of homosexuality. One declared all rabbinic prohibitions on non–penile-anal sex between men to be formally lifted and no longer applicable to Conservative Jews. The other formally declared the necessity of their remaining in effect and instructed Conservative Jews to continue to observe them. Both agreed that a prohibition on male-male anal sex, and adultery with a married woman, retained a die-rather-than-transgress character, and instructed Conservative Jews to continue to observe rabbinic prohibitions on different-sex sexual relations outside of marriage (fornication), although the liberal responsum also found a variety of traditional rules of modesty including prohibitions on contact and seclusion, to be no longer applicable to Conservative Jews. Under the Conservative movement's philosophy of pluralism, local rabbis choose which among the approved alternatives to follow. (See Homosexuality and Conservative Judaism)

Many authorities hold that the requirement to sacrifice one's life does not apply to purely passive behavior, so that, for example, a married woman who is raped is not required to die resisting the rape. Rather, the requirement applies only to playing an initiating role in one of the forbidden sexual acts. See Judaism and homosexuality

Murder
The exception of murder is derived by logic, as the Talmud states (on Pesachim 25b, Yoma 82b, and Sanhedrin 74a): Someone came before Rava and said, "The governor of the city ordered me to slay a certain man, and threatened to kill me if I did not". Rava said to him, "Rather than slay another person, you must permit yourself to be slain, for how do you know that your blood is redder than his; perhaps his blood is redder than yours?" Additional situations
The following requirements are according to Maimonides (Rambam). As stated above, one is normally required to let oneself be killed only for the three cardinal laws; however, in the opinion of Maimonides, certain other special situations also require martyrdom. Public martyrdom

According to Maimonides, one is required to give one's life to avoid desecrating God's name through the public transgression of His commandments. The desecration of God's name is considered the harshest violation of Jewish law, at least as far as heavenly forgiveness is concerned; therefore, if the sin is to be committed in public (for these purposes, in the presence of ten Jewish adults), and the sole purpose of the persecutor is to have the Jew transgress halakha, any prohibition would be considered a matter of yehareg v'al ya'avor. (Note: According to many Orthodox authorities, women count in the minyan of ten Jewish adults required to constitute a "public" for purposes of public martyrdom, one of a number of situations in which women count in a minyan in Orthodox Judaism). If these two conditions are not present, there is no requirement to give one's life, since God's name will not be desecrated by the transgression. For example, if a Jew is being forced to transgress the Shabbat laws for the sake of the forcer's personal profit, he or she would not be required to give his or her life. Resisting persecutions and crises
During a time of crisis for the Jewish faith—for example, if a government or any other power wants to force Jews not to be religious—every prohibition in Jewish law becomes yehareg ve'al ya'avor, and one is to have mesirat nefesh on every negative or positive commandment even when not in public. This is called "Sandal straps" and refers to the traditional Jewish manner of putting on footwear (Put on right, put on left, tie left, tie right). In this situation, one must die even for "Sandal straps". However, if a government or any other power is not opposing the Jewish religion in itself but rather any religion, such as in Russia under the communist regime, then according to some opinions, the above does not apply. It is also considered a crisis for the Jewish faith when a particular requirement within Jewish law is in danger of being outlawed by a government or other power. There is a further qualification: Only the negative commandments could potentially be considered a matter of yehareg v'al ya'avor; one would never be required to sacrifice oneself for one of the positive commandments. Since refraining from the performance of a positive commandment involves no specific action, to do so would not be considered a desecration of God's name, so self-sacrifice would never be required. According to Maimonides, in a situation where one is not required to sacrifice oneself rather than transgress, to do so would be considered suicide, which is strongly forbidden and condemned under Jewish law. Following through and sacrificing one's life in accordance with the law of yehareg ve'al ya'avor is considered to be Kiddush Hashem (sanctification of God's name). See also
Duress
Kiddush Hashem
Pikuach nefesh
Jewish views on suicide
Martyrdom in Judaism

References

Jewish ethical law