On the day that David composed this prayer of praise, he felt like he was finally rid of his enemies. Not that his troubles in life were all truly over, but at least, as David looked around about himself, he didn't see the threats that he had constantly observed for so long. So, appropriately, he sang this song to the sole God of heaven and earth... and thereby worshipped Him vigorously.
Passages like this are sometimes difficult to summarize or to adequately discuss without leaving many parts untouched. Thankfully we can reexamine it again when we reach Psalm 18, since this poem is recorded there too.
In general, it is an expression of David's gratitude. He exults concerning God's deliverance, God's defense and God's divinity (along with much more). David recognized God's ever present help; His immanence; His participation in David's affairs. To make a long story short, David felt the joy of victory and therefore he honorably chose to point to God as the one who is worthy. Essentially, in this psalm, King David said, "Whew! I'm glad that's over!'' And, he said, "Wahoo! Hallelujah... God brought me through!" God is worthy of all our praise! Amen!?