In moments of deep existential crisis, a desperate cry for help can awaken heavenly mercy, even when the one praying does not deserve a response. During a time of extreme pressure and severe distress caused by enemy forces [מצודת ציון], King Jehoahaz of Israel turned to God in prayer [מצודת ציון, ביאור שטיינזלץ].
The primary approach among commentators is that the king was completely unworthy of having his request granted. Both he and the nation continued to cling to the sins of Jeroboam, and idols still stood in Samaria. His prayer was accepted not because of his own righteousness, but strictly because God saw the severe suffering of the Israelites. If not for the terrible distress of the people, the king's prayer alone would never have been enough to bring about a response [מצודת דוד, רלב״ג, חומת אנך, אברבנאל].
The king of Aram had pushed the Israelites to the very edge of total annihilation. This extreme danger threatened to break God's ancient covenant with the forefathers, which promised that the tribes of Israel would never be completely wiped out [רלב״ג]. Acting with endless mercy [חומת אנך], God listened to the nation much like He hears the cry of a poor person, stepping in to lighten the harsh decree and prevent their absolute destruction [מלבי״ם, אברבנאל].
However, this rescue did not happen right away. The heavy oppression from Aram continued for the rest of Jehoahaz's life. Yet, his prayer did have a vital impact. It moved divine wisdom to decree that a savior would eventually arise after the king's death. Ultimately, the prayer succeeded in protecting the remaining Israelites from total ruin during Jehoahaz's reign, setting the stage for the complete salvation that would arrive in the days of his son, Joash [רלב״ג, אברבנאל].