Shmuel II / II Samuel 22:1
וַיְדַבֵּר דָּוִד לַיהוָה אֶת־דִּבְרֵי הַשִּׁירָה הַזֹּאת בְּיוֹם הִצִּיל יְהוָה אֹתוֹ מִכַּף כָּל־אֹיְבָיו וּמִכַּף שָׁאוּל׃
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).
Pshat פְּשָׁט
A song at the end of the road
Rashi: David said this song in old age, when all his troubles had passed and he had been saved from them all. Scripture names Shaul (Saul) separately, though he was among the enemies, because he pursued David more than all. Metzudat David adds a second reading: David sang this song every time he was saved from trouble.
How Rashi and Metzudat David explain it
Remez רֶמֶז
Two versions of one song
Minchat Shai: here it says "from the hand (מִכַּף) of Shaul (Saul)", and in Psalms "from the hand (מִיַּד) of Shaul". Malbim explains why the song is written twice: David composed it in his youth as a general song for all rescues and sang it each time, and in old age, gathering the Psalms as a prayer book for every person, he changed its words so it would fit anyone surrounded by troubles.
How Minchat Shai and Malbim explain it
Drash דְּרָשׁ
A song after reproach
Midrash Tehillim, Rabbi Yudan: David did not say a song until he was reviled by Goliath, until four giants fell and the giant with six fingers. So too Israel will sing in the days of the Messiah only after reproach and the fall of the four kingdoms. Talmud: this song is read as the haftarah on the last day of Pesach, after the song at the sea.
How Midrash Tehillim and Talmud, Megillah explain it
Sod סוֹד
A song from below upward
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