Customarily, when somebody needs to recite Birkat Ha’gomel after emerging safely from a dangerous situation, he recites the Beracha in the synagogue, when the Sefer Torah is read. However, this is not strictly required, and the Beracha may also be recited at other times, as long as a Minyan is present.
The Hatam Sofer (Rav Moshe Sofer of Pressburg, 1762-1839), in one of his responsa, ruled that this Beracha should not be recited during the nighttime. He reasoned that since it is customarily recited at the time of the Torah reading, the Beracha should not be recited at night, when the Torah us not read. The Ben Ish Hai (Rav Yosef Haim of Baghdad, 1833-1909) likewise ruled that Birkat Ha’gomel should not be recited at night, though for a different reason, namely, that this Beracha is recited in place of the Korban Toda (thanksgiving sacrifice) which one would offer in the Bet Ha’mikdash after a situation of danger. Since sacrifices are not brought at night, the Ben Ish Hai writes, Birkat Ha’gomel, which is recited in lieu of a sacrifice, should not be recited at night.
Hacham Ovadia Yosef, however, disputes this position. He noted that we customarily recite Birkat Ha’gomel on Shabbat, even though private sacrifices – such as the Korban Toda – were not offered on Shabbat. Moreover, Rav Eliyahu Mani (Baghdad-Hebron, 1818-1899), in Zichronot Eliyahu, ruled that one who, for whatever reason, cannot recite Birkat Ha’gomel during the day may do so at night. Indeed, it is customary for women to recite Birkat Ha’gomel after childbirth on the night of the traditional Zohar reading, when a Minyan assembles in the home. Thus, one who cannot recite Birkat Ha’gomel during the Torah reading in the synagogue may do so anytime, even at night.
Summary: Those who must recite Birkat Ha’gomel after emerging safely from a dangerous situation customarily recite the Beracha in the synagogue, during the Torah reading. However, this Beracha may be recited anytime in the presence of a Minyan, even during the nighttime.