The following Gemara shares a dramatic story involving R’ Akiva’s firm trust in that everything Hashem does is for the good and how he was thereby saved with this firm belief:
רַבִּי עֲקִיבָא דַּהֲוָה קָאָזֵיל בְּאוֹרְחָא. מְטָא לְהַהִיא מָתָא, בְּעָא אוּשְׁפִּיזָא לָא יָהֲבִי לֵיהּ. אֲמַר: ״כׇּל דְּעָבֵיד רַחֲמָנָא — לְטָב״. אֲזַל וּבָת בְּדַבְרָא, וַהֲוָה בַּהֲדֵיהּ תַּרְנְגוֹלָא וַחֲמָרָא וּשְׁרָגָא. אֲתָא זִיקָא כַּבְיֵיהּ לִשְׁרָגָא. אֲתָא שׁוּנָּרָא אַכְלֵיהּ לְתַרְנְגוֹלָא. אֲתָא אַרְיָה אַכְלֵיהּ לַחֲמָרָא. אֲמַר: ״כׇּל דְּעָבֵיד רַחֲמָנָא — לְטָב״. בֵּיהּ בְּלֵילְיָא אֲתָא גְּיָיסָא, שַׁבְיַיהּ לְמָתָא. אֲמַר לְהוּ: לָאו אֲמַרִי לְכוּ כׇּל מַה שֶּׁעוֹשֶׂה הַקָּדוֹשׁ בָּרוּךְ הוּא הַכֹּל לְטוֹבָה.
Rabbi Akiva was walking along the road and came to a certain city, he inquired about lodging and they did not give him any. He said: Everything that God does, He does for the best. He went and slept in a field, and he had with him a rooster, a donkey and a candle. A gust of wind came and extinguished the candle; a cat came and ate the rooster; and a lion came and ate the donkey. He said: Everything that God does, He does for the best. That night, an army came and took the city into captivity. It turned out that Rabbi Akiva alone, who was not in the city and had no lit candle, noisy rooster or donkey to give away his location, was saved. He said to them: Didn’t I tell you? Everything that God does, He does for the best.
On a similar note is the popular story of Nachum Ish Gam Zu, where his unwavering trust that everything is for the best saved the day:
וְאַמַּאי קָרוּ לֵיהּ נַחוּם אִישׁ גַּם זוֹ — דְּכׇל מִילְּתָא דַּהֲוָה סָלְקָא לֵיהּ, אֲמַר: גַּם זוֹ לְטוֹבָה. זִימְנָא חֲדָא בְּעוֹ לְשַׁדּוֹרֵי יִשְׂרָאֵל דּוֹרוֹן לְבֵי קֵיסָר, אָמְרוּ: מַאן יֵיזִיל — יֵיזִיל נַחוּם אִישׁ גַּם זוֹ, דִּמְלוּמָּד בְּנִיסִּין הוּא. שַׁדַּרוּ בִּידֵיהּ מְלֵא סִיפְטָא דַּאֲבָנִים טוֹבוֹת וּמַרְגָּלִיּוֹת. אֲזַל, בָּת בְּהָהוּא דִּירָא. בְּלֵילְיָא קָמוּ הָנָךְ דָּיוֹרָאֵי וְשַׁקְלִינְהוּ לְסִיפְטֵיהּ וּמְלוֹנְהוּ עַפְרָא.כִּי מְטָא הָתָם, שְׁרִינְהוּ לְסִיפְטֵי, חֲזָנְהוּ דִּמְלוּ עַפְרָא. בְּעָא מַלְכָּא לְמִקְטְלִינְהוּ לְכוּלְּהוּ, אֲמַר: קָא מְחַיְּיכוּ בִּי יְהוּדָאֵי. אֲמַר: גַּם זוֹ לְטוֹבָה. אֲתָא אֵלִיָּהוּ אִדְּמִי לֵיהּ כְּחַד מִינַּיְיהוּ, אֲמַר לֵיהּ: דִּלְמָא הָא עַפְרָא מֵעַפְרָא דְּאַבְרָהָם אֲבוּהוֹן הוּא, דְּכִי הֲוָה שָׁדֵי עַפְרָא — הָווּ סַיְיפֵי, גִּילֵי — הָווּ גִּירֵי, דִּכְתִיב: ״יִתֵּן כֶּעָפָר חַרְבּוֹ כְּקַשׁ נִדָּף קַשְׁתּוֹ״. הַוְיָא חֲדָא מְדִינְתָּא דְּלָא מָצוּ לְמִיכְבְּשַׁהּ, בְּדַקוּ מִינֵּיהּ וְכַבְשׁוּהָ. עֲיַילוּ לְבֵי גִנְזֵיה וּמְלוֹהוּ לְסִיפְטֵיהּ אֲבָנִים טוֹבוֹת וּמַרְגָּלִיּוֹת, וְשַׁדְּרוּהוּ בִּיקָרָא רַבָּה. כִּי אֲתוֹ, בִּיתוּ בְּהָהוּא דִּיּוּרָא, אֲמַרוּ לֵיהּ: מַאי אַיְיתֵית בַּהֲדָךְ דְּעָבְדִי לָךְ יְקָרָא כּוּלֵּי הַאי? אֲמַר לְהוּ: מַאי דִּשְׁקַלִי מֵהָכָא אַמְטִי לְהָתָם. סְתַרוּ לְדִירַיְיהוּ וְאַמְטִינְהוּ לְבֵי מַלְכָּא, אֲמַרוּ לֵיהּ: הַאי עַפְרָא דְּאַיְיתִי הָכָא — מִדִּידַן הוּא. בַּדְקוּהּ וְלָא אַשְׁכְּחוּהּ, וְקַטְלִינְהוּ לְהָנָךְ דָּיוֹרָאֵי.
And why did they call him Nachum of Gam Zu? The reason is that with regard to any matter that occurred to him, he would say: This too is for the good [gam zu letova]. Once, the Jews wished to send a gift [doron] to the house of the emperor. They said: Who should go and present this gift? Let Nachum of Gam Zu go, as he is accustomed to miracles. They sent with him a chest [sifta] full of jewels and pearls, and he went and spent the night in a certain inn. During the night, these residents of the inn arose and took all of the precious jewels and pearls from the chest, and filled it with earth. The next day, when he saw what had happened, Nachum of Gam Zu said: This too is for the good.When he arrived there, at the ruler’s palace, they opened the chest and saw that it was filled with earth. The king wished to put all the Jewish emissaries to death. He said: The Jews are mocking me. Nachum of Gam Zu said: This too is for the good. Elijah the Prophet came and appeared before the ruler as one of his ministers. He said to the ruler: Perhaps this earth is from the earth of their father Abraham. As when he threw earth, it turned into swords, and when he threw stubble, it turned into arrows, as it is written in a prophecy that the Sages interpreted this verse as a reference to Abraham: “His sword makes them as the dust, his bow as the driven stubble” (Isaiah 41:2). There was one province that the Romans were unable to conquer. They took some of this earth, tested it by throwing it at their enemies, and conquered that province. When the ruler saw that this earth indeed had miraculous powers, his servants entered his treasury and filled Nachum of Gam Zu’s chest with precious jewels and pearls and sent him off with great honor. When Nachum of Gam Zu came to spend the night at that same inn, the residents said to him: What did you bring with you to the emperor that he bestowed upon you such great honor? He said to them: That which I took from here, I brought there. When they heard this, the residents of the inn thought that the soil upon which their house stood had miraculous powers. They tore down their inn and brought the soil underneath to the king’s palace. They said to him: That earth that was brought here was from our property. The miracle had been performed only in the merit of Nachum of Gam Zu. The emperor tested the inn’s soil in battle, and it was not found to have miraculous powers, and he had these residents of the inn, put to death.