Shirat Hayam - Birkat Hagomel and Gratitude in Halacha
(לה) וַתַּ֨הַר ע֜וֹד וַתֵּ֣לֶד בֵּ֗ן וַתֹּ֙אמֶר֙ הַפַּ֙עַם֙ אוֹדֶ֣ה אֶת־יְהוָ֔ה עַל־כֵּ֛ן קָרְאָ֥ה שְׁמ֖וֹ יְהוּדָ֑ה וַֽתַּעֲמֹ֖ד מִלֶּֽדֶת׃

(35) She conceived again and bore a son, and declared, “This time I will praise the LORD.” Therefore she named him Judah. Then she stopped bearing.

(יב) אִ֣ם עַל־תּוֹדָה֮ יַקְרִיבֶנּוּ֒ וְהִקְרִ֣יב ׀ עַל־זֶ֣בַח הַתּוֹדָ֗ה חַלּ֤וֹת מַצּוֹת֙ בְּלוּלֹ֣ת בַּשֶּׁ֔מֶן וּרְקִיקֵ֥י מַצּ֖וֹת מְשֻׁחִ֣ים בַּשָּׁ֑מֶן וְסֹ֣לֶת מֻרְבֶּ֔כֶת חַלֹּ֖ת בְּלוּלֹ֥ת בַּשָּֽׁמֶן׃
(12) If he offers it for thanksgiving, he shall offer together with the sacrifice of thanksgiving unleavened cakes with oil mixed in, unleavened wafers spread with oil, and cakes of choice flour with oil mixed in, well soaked.
(יד) יֽ֭וֹצִיאֵם מֵחֹ֣שֶׁךְ וְצַלְמָ֑וֶת וּמוֹסְר֖וֹתֵיהֶ֣ם יְנַתֵּֽק׃

(14) He brought them out of deepest darkness, broke their bonds asunder.

ת"ר בו ביום דרש רבי עקיבא בשעה שעלו ישראל מן הים נתנו עיניהם לומר שירה וכיצד אמרו שירה כגדול המקרא את הלל והן עונין אחריו ראשי פרקים משה אמר (שמות טו, א) אשירה לה' והן אומרים אשירה לה' משה אמר כי גאה גאה והן אומרים אשירה לה'
§ The Sages taught: On that same day Rabbi Akiva taught that at the time that the Jewish people ascended from the split sea they set their eyes on reciting a song of gratitude to God. And how did they recite the song? In the same manner as an adult man reciting hallel on behalf of a congregation, as his reading enables all who hear to fulfill their obligation, and the congregation listening merely recite after him the chapter headings of hallel. So too, by the sea, Moses said: “I will sing unto the Lord” (Exodus 15:1), and the people said after Moses: “I will sing unto the Lord.” Moses continued and said: “For He is highly exalted” (Exodus 15:1), and they said once again the chapter heading: “I will sing unto the Lord.”

אמר רב יהודה אמר רב ארבעה צריכין להודות יורדי הים הולכי מדברות ומי שהיה חולה ונתרפא ומי שהיה חבוש בבית האסורים ויצא

Rav Yehuda said that Rav said: Four must offer thanks to God with a thanks-offering and a special blessing. They are: Seafarers, those who walk in the desert, and one who was ill and recovered, and one who was incarcerated in prison and went out. All of these appear in the verses of a psalm (Psalms 107).

מאי מברך אמר רב יהודה ברוך גומל חסדים טובים

The Gemara asks: What blessing does he recite? Rav Yehuda said: Blessed is…Who bestows acts of loving-kindness.

(א) ברכת הודאת היחיד. ובו ט סעיפים:
ארבעה צריכים להודות יורדי הים כשעלו ממנה והולכי מדברות כשיגיעו ליישוב ומי שהיה חולה ונתרפא ומי שהיה חבוש בבית האסורים ויצא וסימנך וכל החיי"ם יודוך סלה "חולה "יסורין "ים "מדבר:

(ב) ומה מברך בא"י אמ"ה הגומל לחייבים טובים שגמלני כל טוב והשומעים אומרים מי שגמלך כל טוב הוא יגמלך כל טוב סלה:

(

(א) אַרְבָּעָה צְרִיכִים לְהוֹדוֹת. יוֹרְדֵי הַיָּם כְּשֶׁיַּגִּיעוּ לִמְחוֹז חֶפְצָם, וְכֵן הוֹלְכֵי מִדְבָּרִיּוֹת אוֹ בִּשְׁאָר דֶּרֶךְ שֶׁמֻּחְזָק שֶׁיֶּשׁ בּוֹ סַכָּנָה, כְּשֶׁיַּגִּיעוּ לִמְחוֹז חֶפְצָם, וּבִכְלָל זֶה גַּם מִי שֶׁהָיָה בְּסַכָּנָה אַחֶרֶת וְנִצֹּל הֵימֶנָּה, כְּגוֹן שֶׁנָּפַל עָלָיו כֹּתֶל אוֹ נְגָחוֹ שׁוֹר אוֹ שֶׁבָּאוּ עָלָיו לִסְטִים בַּדֶּרֶךְ וְשׁוֹדְדֵי לַיְלָה וְנִצַּל מֵהֶם וְכַדּוֹמֶה, וּמִי שֶׁהָיָה חוֹלֶה שֶׁיֵּשׁ בּוֹ סַכָּנָה, כְּגוֹן מַכָּה שֶׁל חָלָל, אוֹ שֶׁהָיָה מוּטָל בַּמִּטָּה שְׁלשָׁה יָמִים מֵחֲמַת הַחֹלִי וְנִתְרַפֵּא וְהוֹלֵךְ עַל בָּרְיוֹ. וּמִי שֶהָיָה חָבוּשׁ בְּבֵית הָאֲסוּרִים, אֲפִלּוּ רַק עַל עִסְקֵי מָמוֹן וְיָצָא. וְסִימָנְךָ וְכָל הַחַיִּי"ם יוֹדוּךָ סֶלָה, חוֹלֶה, יִסּוּרִים, יָם, מִדְבָּר. מַה מְבָרֵךְ. בָּרוּךְ אַתָּה ה' אֱלֹקֵינוּ מֶלֶךְ הָעוֹלָם, הַגּוֹמֵל לַחַיָּבִים טוֹבוֹת שֶׁגְּמָלַנִי כָּל טוֹב. וְהַשּׁוֹמְעִים אוֹמְרִים, מִי שֶׁגּמָלְךָ טוֹב הוּא יִגְמָלְךָ כָּל טוֹב סֶלָה.

(1) On four [occasions] a person must thank God [for His goodness];1A boy under the age of thirteen does not say Hagomeil. The accepted minhag is that women do not recite this berachah either. The acharonim (authorities of the recent past) offer the reason, that this berachah is recited in the presence of a minyan, which does not apply to women. (Mishnah Berurah 219: 1) 1] after crossing the ocean and reaching his destination; 2] after crossing the desert or any other dangerous road and reaching his destination; included in this rule is also one who was saved from any other peril, as when a wall caved in on him or an ox lunged at him, ready to gore him, or robbers attacked him on the road, or thieves at night and he was saved from them, or from similar perils; 3] one who suffered from serious illness or a serious injury or he was confined to bed for [at least] three days due to an illness and he recovered, his health restored; 4] one who was in prison even if [he was in prison] only because of monetary matters and he was released. [The following phrase may serve as] a mnemonic device: "All those who are alive thank you, selah." [The word chayimחיים — forms the acronym of] choleh—a sick person, yisurim —a person suffering [in prison], yam—(crossing the) ocean, midbar—(crossing the) desert. What berachah should they say? Baruch ata Adonoy Elokeinu melech ha'olam hagomeil lechayavim tovos shegemalani kol tov, [Blessed are You, Hashem, our God, King of the universe, Who bestows good things upon the guilty, Who has bestowed every goodness upon me]. The listeners should respond: mi shegemalecha tov hu yigmalecha kol tov selah, [May He Who has bestowed goodness upon you continue to bestow every goodness upon you forever].