The title of Psalm 18 places it in history: David spoke the words of this song in the day that Yahweh delivered him from the hand of all his enemies and from the hand of Saul. It is one of the longest psalms, and a nearly identical version appears in 2 Samuel 22. David opens with personal love, I love you, Yahweh, my strength, and then a cascade of images for God's protection: rock, fortress, deliverer, shield, horn of my salvation, and high tower.
The middle section describes David's rescue in dramatic language. The cords of death and of Sheol surrounded him, and in his distress he cried to God. Then the earth shook, the heavens bowed, and God came down in thick darkness, thunder, and lightning. Such language pictures the power of God's response. The rescue itself is gentle and personal: He took me. He drew me out of many waters. He brought me out also into a large place. He delivered me, because he delighted in me.
The final section praises God for giving victory in battle. As for God, his way is perfect. Yahweh's word is tried. He is a shield to all those who take refuge in him. God lights David's lamp, makes his feet like deer's feet, and gives him strength. The psalm ends with a royal promise: He gives great deliverance to his king, and shows loving kindness to his anointed, to David and to his offspring, forever more. In the New Testament, Paul quotes verse 49 about the nations praising God (Romans 15:9).