II Samuel22: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).

II Samuel 22:1

וַיְדַבֵּר דָּוִד לַיהוָה

Shmuel II / II Samuel 22:1 · Drash

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).

Drash דְּרָשׁ

A song after reproach

A song of victory comes after the hardest trials, not before them. The Midrash sees in David's life a model for the whole people and for the end of days.

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

Midrash Tehillim Who spoke to the Eternal

What is "this song"? Rabbi Yudan said: this is what is written: "I was as a wonder to many" (Tehillim / Psalms 71:7). David said: I did not say a song until I was reviled, until four fell by my hand, and until the man with [extra] fingers fell by my hand. So too Israel will not say a song until they are reviled and until four fall by their hand, and the man with fingers. This is "I was as a wonder to many": I am a good sign for Israel.

How was he reviled? Goliath the Philistine taunted Israel and cursed David, and fell by his hand (Shmuel I / I Samuel 17). And the man with fingers: "And there was a man of great stature, and the fingers of his feet were six and six" (Shmuel II / II Samuel 21:20). And four fell before him: "These four were born to the giant in Gath" (Shmuel II / II Samuel 21:22). And right after: "And David spoke to the Eternal the words of this song" (Shmuel II / II Samuel 22:1).

So too when the Messiah comes, soon in our days, they will not say a song until the Messiah is reviled, as it says: "with which they reviled the footsteps of Your anointed" (Tehillim / Psalms 89:52), and until the man with fingers falls before him, this is the wicked kingdom of idolaters, as it says: "And the toes of the feet, part of them iron" (Daniel 2:42), and until the four kingdoms fall before him, as it says: "And I will gather all the nations to Jerusalem to battle" (Zecharyah / Zechariah 14:2). At once: "And the Eternal will go out and fight" (Zecharyah / Zechariah 14:3). At that hour they will say a song, as it says: "Sing to the Eternal a new song, for He has done wonders" (Tehillim / Psalms 98:1).

Talmud, Megillah The haftarah of the last day of Pesach

On the last festival day of Pesach they read [from the Torah] "And it came to pass, when he let go" (Shemot / Exodus 13:17) and read the haftarah "And David spoke" (Shmuel II / II Samuel 22:1). And on the next day, "Every firstborn" (Devarim / Deuteronomy 15:19) and the haftarah "This very day" (Yeshayahu / Isaiah 10:32).

Takeaway

The haftarah is a passage from the Prophets read in the synagogue after the Torah reading. David's song is read twice a year: on the Shabbat of Haazinu, after Moshe's (Moses') song, and on the seventh day of Pesach, after the song at the sea.
The four born to Rafah (הָרָפָה) in Gath fell by the hand of David and his warriors (Shmuel II / II Samuel 21:22). One of them had six toes on each foot (Shmuel II / II Samuel 21:20).
The four kingdoms in the Midrash are the four empires under whose rule Israel lived: Babylon, Media, Greece and Edom.