It is stated in Yakut Mei’am Lo’aiz: “Why did Moshe Rabenu wait to daven until right before the nation entered Eretz Yisroel? He wanted to teach us that even if a sharp sword is on a person’s throat, he should not refrain from praying for mercy. He should still pray to Hashem to save him from death and he should not say that he has no hope of being saved.”
The Gemara relates (Brachos 10A) that Chizkiyahu Hamelech became very sick. Yeshaya Hanavi came to visit him and told him to write his will because he was going to die. He also told him that he would have no share in Olam Haba. Chizkiyahu asked what sin he had committed to deserve this punishment, and Yeshaya told him that it was because he had never tried to get married.
Chizkiyahu told him that he had seen with ruach hakodesh that he would have bad children. He decided that it would be better not to get married and to have no children than to have bad children.
Yeshaya told him that this was not his concern. He should not have mixed in with Hashem’s calculations. Since he is commanded to marry, he must do his part and he has to let Hashem do what He wants.
Chizkiyahu told him, “Give me your daughter as a wife and in the merit of both of us together, we will have good children.”
Yeshaya replied, “What’s done is done. The decree of your imminent death has already been issued in Shomayim.”
Chizikyahu said, “Son of Amotz, take your prophecy and leave! I have a tradition from my ancestors that even if a sharp sword is upon one’s neck, he should not give up hope of being saved!”
Chizkiyahu was very sick and certainly could not have full concentration on his prayers at this time. Still and all, he davened to Hashem for a refuah and his prayers were answered.
This is as Dovid Hamelech says (Tehillim 145:18): “Hashem is close to all who call out to Him, to all those who call out to Him with truth.” This means that Hashem is close to anyone who calls out to Him in a difficult time, even if his tefillah is not uttered with full concentration and devotion because he is so broken and pained. Hashem hears even a prayer like that and saves the person from his pain. However, the pasuk adds that one must call out to him “in truth”, with as much concentration as he can muster under the circumstances.
Dovid Hamelech further states (Tehillim 118:5): “From the straits I called out to Hashem. Answer me in the vast expanse, Hashem.” He is saying that one should call out to Hashem when he is in pain, rather than relying on others to pray for him, even though he cannot have full kavannah as a result of his pain and anguish. Not only does Hashem answer such a prayer, he even provides a “vast expanse” of goodness.
Chizkiyahu stood up and began to daven to Hashem from the depths of his heart. He said, “Ribono Shel Olam. The Shunamis only made one small room for Elisha Hanavi to have a place to stay and you brought her son back from death in that merit. My ancestor, Shlomo Hamelech, covered the entire Heichal of the Bais Hamikdosh with silver and gold for Your honor. You certainly should remember this zechus and heal me from my sickness. And remember that I served You will a complete heart!”
He cried copiously to Hashem and his prayers were accepted. And Hashem added 15 years to his life.
We learn from this that even if death is decreed upon a person and he is lying in bed dying, he should not stop davening to Hashem to annul the decree.
