Shemot / Exodus 15:1 · Drash
אָז יָשִׁיר־מֹשֶׁה וּבְנֵי יִשְׂרָאֵל אֶת־הַשִּׁירָה הַזֹּאת לַיהוָה וַיֹּאמְרוּ לֵאמֹר אָשִׁירָה לַיהוָה כִּי־גָאֹה גָּאָה סוּס וְרֹכְבוֹ רָמָה בַיָּם׃
Then Moshe and the children of Israel sang this song to the Eternal, and they spoke, saying: "I will sing to the Eternal, for He is highly exalted, the horse and its rider He has thrown into the sea.
Drash דְּרָשׁ
They believed, and they sang
A song is rarely born of doubt. First you stop being afraid and begin to trust, and then the voice rises by itself. The midrash links the song at the sea with the faith that came one verse before it.
Shemot Rabbah: in Egypt the people believed, and then stopped believing again. At the sea they saw how the Holy One, blessed is He, executes judgement on the wicked, and believed. For this faith the spirit of holiness rested on them, and they sang. The word "then" itself speaks of trust.
How Shemot Rabbah explain it
Shemot Rabbah
"Then Moshe (Moses) sang". Of this it is written: "And they believed His words, they sang His praise" (Tehillim / Psalms 106:12). Rabbi Abbahu said: although it is already written that they believed, while still in Egypt, as it says: "And the people believed" (Shemot / Exodus 4:31), they stopped believing again, as it says: "Our fathers in Egypt did not understand Your wonders" (Tehillim / Psalms 106:7).
When they came to the sea and saw the might of the Holy One, blessed is He, how He executes judgement on the wicked, as it says: "and my hand takes hold of judgement" (Devarim / Deuteronomy 32:41), and He sank the Egyptians in the sea, at once "and they believed in the Eternal" (Shemot / Exodus 14:31). And by the merit of faith the spirit of holiness rested on them, and they sang a song. This is what is written: "Then Moshe and the children of Israel sang".
And "then" (אָז) is nothing but a word of trust, as it says: "And it came to pass from the time (מֵאָז) that he set him over his house" (Bereshit / Genesis 39:5), and it is written: "and all that he had he put into his hand" (Bereshit / Genesis 39:4). Thus: "And they believed His words, they sang His praise".
Takeaway
The verse before the song: "and they believed in the Eternal and in Moshe His servant" (Shemot / Exodus 14:31). The midrash reads both verses together: faith, and after it song.
The spirit of holiness (רוּחַ הַקֹּדֶשׁ) is inspiration from above, which lets a person speak words of the Most High.
"From the time that he set him over his house" is about the Egyptian Potifar, who entrusted his whole house to Yosef (Joseph). The midrash hears this trust in "then" (אָז).