Prophet David is well known in all three Abrahamic faiths, Islam, Christianity, and Judaism. He is a central figure in Jewish history, reigning in United Kingdom of Israel and Judah, from c. 1010–970 BCE.
David is also a common figure in art and iconography across the centuries and his story has even been popularized in 20th century culture, most notably in Leonard Cohen’s iconic song Hallelujah.
In Islam, David is recognized as a Prophet, a messenger, and a king. His story differs slightly from the Biblical traditions and has at times been a cause of disagreement.
Muslims do not accept the sins of adultery and murder attributed to David in the Bible because Islam teaches us that the Prophets do not commit such grave crimes.
Muslims also believe that what God tells us in Quran, and what Prophet Muhammad explains to us in his traditions, is the final word on a subject. It is in these two sources that we find that David’s most significant role was his piety. His righteousness stands out, and his submission to God shapes his rise to power.
David is descended from Judah, the son of Prophet Jacob who is in turn descended from Prophet Abraham. He is among the Prophets that were given a book revealed by God; the Psalms, known in Islam as the Zabur.
Zabur is variously translated as song, music, singing and story. David is known to have used his beautiful voice to praise God. And scholars of Islam interpret this as reciting the psalms in the same way that the Quran is recited.
The Battle with Goliath
Long before his prophethood and before the psalms were revealed, in roughly 1010 BCE, David was the younger brother of three men who went to war against the Philistines.
At a time in the war when King Saul appeared to be leading the losing side, it was young David that turned the tide.
The Quran tells us that among the army were many people who had lost their faith in God. He (God) tests them by the banks of a river and David is amongst the very few who prove to God that their belief is strong and unwavering.
When they return to the battle, David kills Goliath. The Quran does not give details of the incident, however the Biblical texts say that David used his slingshot to kill the giant man.
Islamic scholars tell us that Biblical stories that do not contradict or go against the Quran may indeed be true because the Torah was a revealed message from God that only became corrupted over time.
David was an unimportant person in the community, he was with the army only to keep his father informed of the fate of his brothers. Suddenly overnight he was thrust into an exalted position. The people expected David to be the successor of King Saul and King Saul married David to his daughter. It is at this time that David is given the gift of prophethood.
… and God gave him the Kingdom and the prophethood and taught him that which He willed… (Quran 2:251)
The Humble Leader
After killing Goliath, David did not brag about his new found fame and position. Rather he went into the desert, where he glorified God, singing His praises and contemplating His favors.
God made the mountains and the birds sing with David in the afternoons and in the mornings. David was grateful and humble and God granted him this miracle. He could not only sing with the birds and mountains, but he could also understand the languages of the birds and beasts.
David was very pious. He divided his day into four parts, in one he earned his own living and rested, in another he listened to the complains of his people, in the third he preached sermons and the final part he spent time praising God and praying. 
Prophet Muhammad used David’s story and lifestyle to help the believers understand the nature of piety, repentance, and submission to the will of God.
The prayer which God loves the most is the prayer of David. The fast which God loves the most is that of David. He would sleep for half of the night, stand up in prayer for a third and then sleep for a sixth. He would fast every other day… (Al-Bukhari)
The error that is referred to here is what Quran calls, the account of the litigants. One day when David was in his prayer place, two brothers climbed over the wall and asked David to judge between them. They were, in fact, two angels sent to test David.
David was surprised when they entered his chamber and began to tell him the nature of their dispute. One brother had ninety nine ewes and wanted the one ewe that his brother possessed.
David ruled in favor of the brother who had only one ewe without hearing the full case. Suddenly he realized that he had made a mistake and that this was a test from God. He bowed down to God begging forgiveness.
Prophet David was a fair and honorable ruler who brought peace and prosperity to the land. God makes David vicegerent of the earth to judge between men in truth.
He centralized power developed a significant military organization and made his capital at Jerusalem. David also delivered God’s message and used his melodious voice to delight people and remind them of God. When he recited the Psalms the people, animals, birds and everything in nature listened and glorified God.
 The Stories of the Prophets. Prophet David. Ibn Kathir
(From Discovering Islam archive.)