When Rabbi Akiva was in prison  Rabbi Yehoshua HaGarsi was permitted to wait on him. Every day they would bring to Rabbi Akiva a measured amount of water. One day, the jailer encountered Rabbi Yehoshua and said to him: “You have too much water today. Perhaps you need it to dig out of the prison?”
The jailer spilled out half the water and gave him the other half. When he came to Rabbi Akiva, he said to him: “Yehoshua, don’t you know that I am old and my life depends on your life?”
He then related to him the whole incident. Rabbi Akiva said: “Give me water so that I can wash my hands (before eating bread).”
Rabbi Yehoshua replied: “There isn’t even enough water to drink; is there enough for you to spare to wash your hands?”
Rabbi Akiva responded: “What can I do? The Rabbinic laws carry the death penalty! It is better that I die a death caused by myself by not drinking enough rather than transgress the will of my colleagues.”
It is said that Rabbi Akiva tasted nothing until he brought him water and he washed his hands. When the sages heard of this they remarked: “If in his old age he is like this, how much more so must he have been in his youth ; and if in prison he is like this, how much more so must he have been when not in prison.” (Gemara Eruvin 21b)
Rambam famously rules  that in a situation where Halachah permits one to violate the Torah rather than sacrifice his life, Halachah in fact demands that he violate the Torah. Whenever Halachah does not mandate surrendering one’s life, one has the obligation to save his life, even if this entails violating the Torah. Surely this principle would apply all the more so to transgressing Rabbinic laws, so why do the sages praise Rabbi Akiva’s conduct?
Nimukei Yosef (Sanhedrin 18a) claims that although the Rambam forbids martyrdom when Halachah does not require it, a prominent, righteous Jew may give his life if he sees that the people of his time are disloyal to the Torah and he seeks to impress upon them the importance of Mitzvot. In such a situation, even if Halachah does not mandate martyrdom to avoid violating the given transgression, the righteous leader may, indeed, surrender his life in the sanctification of God’s name.
Alternatively, MaHaritz Chayot answers that if Rabbi Akiva’s life had been in certain danger then it would have been forbidden for him to behave strictly. The situation described in our Gemara was not one of certain danger though, because it was quite plausible  that more water would be brought, as was indeed the case.
1. Rabbi Akiva was imprisoned by the Romans for teaching Torah in public.
2. How can this statement be reconciled with Avot d’Rabbi Natan 6:2 which states that Rabbi Akiva was ignorant until the age of forty? We could suggest that our phrase “in his youth” refers to his forties.
3. Hilchot Yesodei HaTorah 5:4
4. Rav Shmuel Eliezerov cites this Nimukei Yosef to justify the actions of Chananyah, Mishael and Azaryah, referenced in Gemara Pesachim 53b.
5. Apparently, Rabbi Akiva was aware that he was a high profile prisoner whom the Romans would not want to die of thirst.