When describing the laws forbidding a Jew to collect interest on a loan made to another Jew, the Torah uses the expression "וחי אחיך עמך," "that your brother (a fellow Jew) may live along with you" (ויקרא כ"ה:ל"ו). The Gemara in Bava Metzia (דף ס"ב.) presents a well-known dispute in connection with which this phrase is applied in a completely different context. The Gemara discusses a case of two travellers, one of whom has a canteen with water, but not enough for both of them to survive on before reaching the nearest town. If they will each drink some of the water, it will not suffice for either one and they will both die, whereas if one will keep all the water for himself, he will indeed survive and reach the town, although the other will die. Ben Petura rules that in such a case, they should split the water and each drink even if it means they will both die, whereas Rabbi Akiva, citing our phrase וחי אחיך עמך, and apparently stressing the word עמך, along with you, rules that the one who has the water should drink it all himself even if his friend will die as a result, because חייך קודמים לחיי חבירך; where a choice must be made, one's own life takes precedence over someone else's. One's responsibility to save another human being's life exists only when he will be able to live עמך, along with you, but if not, then preserving one's own life comes first; one therefore may not give up one's own life to save someone else's. If, however, one can save someone else's life without giving up his own, he is certainly obligated to do so, as the Rambam (פרק א' מהל' רוצח הלכה י"ד) and the Shulchan Aruch (חושן משפט סימן תכ"ו סעיף א') state clearly, based on a Gemara in Sanhedrin (דף ע"ג.).
What if one can save someone else's life in such a way that he won't definitely be giving up his own life, but there will be a possible danger to his own life? In other words, is one obligated, or even allowed, to put himself in a potentially dangerous and life threatening situation in order to save the life of another who is definitely in danger? Rav Yosef Karo, both in his Kessef Mishneh on the above cited Rambam (שם) and in his Beis Yosef on the Tur (חו"מ שם בד"ה ומ"ש), quotes that the Hagahos Maimoniyos cites a Yerushalmi which indicates that one is indeed obligated to enter into a potentially dangerous situation in order to save someone who is definitely in danger, and he suggests that the reason is that it is only a possible danger for the one person as opposed to a definite danger for the other. (It should be noted that this comment of the Hagahos Maimoniyos does not appear in the standard edition of the Rambam's Mishneh Torah, but in a different manuscript now printed in the back of the Mishneh Torah published by Rabbi Shabsi Frankel).
The Hagahos Maimoniyos there does not identify the location of this Yerushalmi, but the Netziv, in his commentary Haamek She'eilah on the Sheiltos (שאילתא קכ"ט אות ד') points to the Yerushalmi in Terumos (פרק ח' הלכה ד', דף מ"ז.) which relates that a certain Amora was once trapped in a dangerous place, and whereas one of his friends had abandoned hope of saving him, Reish Lakish expressed the readiness to go save him even if it meant that his own life would be lost in the process. This would seem to indicate that one is indeed obligated to save another from certain death even if doing so will endanger his own life. The Netziv (שם) suggests that some understand this to be the opinion as well of Rav Achai Gaon, the author of the Sheiltos (שם), and the Chavos Yair (שו"ת חות יאיר סימן קמ"ו) seems to accept this as the Halacha, noting that such is the understanding of the aforementioned Gemara in Bava Metzia which implies that the one who has the water should drink it all himself only if it is clear that should they split it, they'll both die, but if it's possible that they'll both live, they must share it. In other words, the one who has the water must share it even though that may possibly endanger his own life, because this action may save his friend from certain death.
The S'ma, however, points out (חו"מ שם ס"ק ב') that this ruling of the Yerushalmi is not brought down in the Shulchan Aruch by either the Mechaber or the Ramo, and he posits that this is because the major Poskim, namely, the Rif, the Rambam, the Rosh, and the Tur, all omit this view. The Pischei Teshuvah (שם ס"ק ב') quotes from a Sefer called Agudas Eizov that the reason for this omission is that although it may be the position of the Yerushalmi that one must risk endangering one's life to save someone else from certain death, the Bavli disagrees, and the Halacha thus follows the Bavli that one is indeed not required to jeopardize one's own life to save another person.
As for where exactly the Bavli disagrees about this, Rav Ovadyah Yosef (שו"ת יחוה דעת חלק ג' סימן פ"ד), in discussing the issue of donating for a kidney transplant, also cites this Agudas Eizov, quoting that the Bavli referred to is a Gemara in Niddah (דף ס"א.) which states that Rabbi Tarfon did not want to hide certain people concerning whom there was a rumor that they had committed a murder and who were thus wanted by the authorities. Tosafos (שם בד"ה אטמרינכו) quotes from the aforementioned Sheiltos (in a version different from the text we have) that Rabbi Tarfon's reasoning was that if he'll hide them, thereby saving their lives, he'll be endangering his own life because if he's caught harboring criminals, he'll be executed himself. In other words, according to the Agudas Eizov, he didn't want to possibly endanger his own life in order to save others from certain danger, against the above Yerushalmi.
The above cited Netziv (שם), however, seems to learn this Gemara differently, stressing that Rabbi Tarfon's refusal was based on his suspicion that those men were actually guilty, and that had he been sure they were innocent, he would indeed have hidden them, despite the potential danger. Moreover, Rashi (שם בד"ה מיחש) also seems to say that Rabbi Tarfon refused to hide them not because of any danger to himself, but because he felt that perhaps they're guilty, in which case it's forbidden to hide them. Rabbeinu Yehudah HaChassid, in his Sefer Chassidim (סימן תרפ"ג), in fact rules, referring to this Gemara, that one should not give refuge to a murderer, whether a Jew or a non-Jew. There is therefore no clear proof from this Gemara that the Bavli disagrees with the Yerushalmi about risking one's life to save someone else.
The Netziv (שם), however, quotes the above cited Gemara in Sanhedrin (דף ע"ג.) which states that in order to save someone's life, a person must even be prepared to exert great effort and spend money, if necessary; Rashi (שם בד"ה קמ"ל) explains that one must look into every possible way to save another's life. No mention is made there, however, of endangering one's own life to save the other person, implying that the Bavli here indeed disagrees with the Yerushalmi. Elsewhere in his commentary to the Sheiltos, the Netziv (העמק שאלה לשאילתא קמ"ז אות ד'), suggests that this dispute between the Bavli and the Yerushalmi is really a dispute between Tannaim in the Gemara in Nedarim (דף פ:), and that ultimately, this is the crux of the dispute cited above between Ben Petura and Rabbi Akiva. He explains that Ben Petura cannot possibly hold that the two travellers should split the water if they will both definitely die that way, since that would be pointless. Rather, Ben Petura holds that they should both drink and live another day or two, because, although they won't reach the town, they may somehow find some more water; the one who has the water must thus give up some despite the fact that he will be endangering his own life thereby, because he is required to do this to save his friend from certain death. Rabbi Akiva, however, disagrees, and holds that because חייך קודמים, one does not have to put himself into potential danger to save someone else.
Regarding the statement of Reish Lakish in the Yerushalmi (שם), Rav Ovadyah Yosef (שם) quotes some who hold that the Halacha doesn't follow him, but rather follows the other view quoted there; the Netziv, in both places cited above, suggests that he was acting with מדת חסידות, a sense of piety not required by the Halacha. It is worth noting, though, that the Radbaz (שו"ת הרדב"ז חלק ג' סימן תרכ"ה) rules that one need not give up any limb to save another's life, although he may do so, but if one would give up a limb whose absence would endanger his own life, he is labeled a חסיד שוטה, a pious idiot. The Aruch HaShulchan (חו"מ שם סעיף ד') writes, though, that although one indeed need not jeopardize his own life to save another, one shouldn't be excessively careful or overly protective of his own life if he can save somebody in danger; the Pischei Teshuvah (שם) quotes that one who is may someday find his own life in such danger.