Psalm 18. Both open with nearly the same heading: the narrator's line that David spoke these words "on the day when the Lord delivered him from the hand of all his enemies and from the hand of Saul" (2 Samuel 22:1). The lines that follow are nearly the same too. Psalm 18:1 adds an opening line, "I love you, O Lord, my strength," and where 2 Samuel 22:33 has "opened wide my path," Psalm 18:32 has "made my way safe."
Differences that small are the kind that creep in as a text is copied over centuries, so the pair lets a reader watch that happen inside the Bible. In the song God hears the singer "from his temple" (2 Samuel 22:7). The note in the New Oxford Annotated Bible takes that as a sign the psalm was written after David's time, though the word may also mean God's home in heaven.
Learn the Bible.
Not just the stories, but the history, authorship, and scholarship behind it.