In the second book of Samuel, David at the age of 37, after many battles, became King of Israel.
He worshipped God, and ruled the Israelites wisely and well for many years.
However, sin lead to King David's downfall. Looking down from his palace, he saw a woman bathing and was attracted to her. It turned out that she, Bathsheba, was married to one of David's soldiers. David sent her husband to the front lines of battle, which lead to his death, and married Bathsheba.
The prophet Nathan rebuked King David (for his sin), and it is a measure of David's humility that he repented and turned back to God.
However, after this point, and through the rest of his 30-year reign, David endures many heartbreaking situations in his own home.
But David remained faithful to God for the rest of his life.