Following moments of intense crisis and danger, a profound sense of absolute trust in God can emerge from within, leading to sudden salvation and overwhelming joy. David declares that God is his ultimate source of strength and protection, relying on Him entirely. Even when physical assistance arrives through the hands of people, it is ultimately because God directed them to provide that help [אבן עזרא].
Historically, this outpouring of gratitude stems from a specific life-threatening event: David's rescue from Ishbi-benob, who sought to kill him. Despite the terrifying danger, David maintained complete faith that God would save him. His trust was realized when Abishai the son of Zeruiah stepped in to rescue him [רד״ק]. Naturally, the immediate aftermath of this survival brought immense gladness to his heart for the intervention he received [מצודת ציון, מצודת דוד, ביאור שטיינזלץ].
However, this happiness carries deeper layers. On an intellectual level, this harsh event led David's men to swear that he would no longer go out to battle. David rejoiced at this, knowing he would now be free from worldly conflicts and able to fully immerse himself in the ways of God [רד״ק]. Furthermore, there was a rapid, internal shift in his trust. The spiritual joy and sense of rescue actually filled his heart before the physical salvation even took place. The moment he turned to God, a heavenly joy washed over his soul, transforming his sadness into song, and it is for this internal transformation itself that he offers thanks [אלשיך].
Overflowing with this joy, David promises to express his gratitude and give glory to God [מלבי״ם, ביאור שטיינזלץ]. He does this using his own voice [מאירי], offering praise through his hymns [רד״ק, ביאור שטיינזלץ], and specifically through a unique song he composed for the occasion [מצודת דוד]. Another perspective suggests this is a pledge to thank God even more profoundly in the future than he does in his current song [אבן עזרא בשם ר׳ משה הכהן]. Ultimately, the core message of his praise is the clear recognition that God grants strength and salvation to everyone who depends on Him, and especially to His anointed leader [רש״י].