Shmuel II / II Samuel 22:1 · Sod
וַיְדַבֵּר דָּוִד לַיהוָה אֶת־דִּבְרֵי הַשִּׁירָה הַזֹּאת בְּיוֹם הִצִּיל יְהוָה אֹתוֹ מִכַּף כָּל־אֹיְבָיו וּמִכַּף שָׁאוּל׃
And David spoke to the Eternal the words of this song on the day the Eternal rescued him from the hand of all his enemies and from the hand of Shaul (Saul).
Sod סוֹד
A song from below upward
It is one thing to give thanks in the midst of the struggle, another when life is lived and the heart is calm. The mystical tradition tells songs apart by where they rise from.
Zohar: this song is David's praise, because he said a song from below upward and merited this level. But he said it only at the end of his days, when he was more complete, as taught: "Do not trust yourself until the day of your death." And he merited it because he was then at rest on all sides: "on the day the Eternal rescued him from the hand of all his enemies".
How Zohar explain it
Zohar And David spoke to the Eternal the words of this song
It is written: "And David spoke to the Eternal the words of this song." Here is David's praise, because he said a song from below upward and merited this level. And he said this song only at the end of his days, when he was more complete than [before], as we learned: "Do not trust yourself until the day of your death" (Mishnah Avot 2:4). And why did David merit here to say a song from below upward at the end of his days? Because he was at rest on all sides, as it is written: "on the day the Eternal rescued him from the hand of all his enemies".
Takeaway
"Do not trust yourself until the day of your death" are the words of Hillel (Mishnah Avot 2:4): a person cannot be sure of himself while he lives.
Recanati (on the portion Vayeilech) brings the words of the Zohar: Moshe (Moses) rose from below upward. Both songs, Moshe's and David's, are read on the same Shabbat.