In 1 Samuel 13:13,14, the prophet Samuel tells the then-current king of Israel that none of his sons will sit the throne after him; instead, he says, “Jehovah hath sought him a man after his own heart” to be Israel’s second king (14). That man’s name was David.
But the thing is, when we read about David’s life in the Scriptures, without getting into the gory details, what we learn about the “man after [God’s] own heart” is that he was, frankly, a mess. Thus, the question arises: In what way, exactly, was David “a man after [God’s] own heart”? There are two keys to answering this question.
One key is the description found in 1 Sam. 18:14—“And David behaved himself wisely in all his ways; and Jehovah was with him” (cp. 5,15,30). This is encouraging—for even though, as a rule, David “behaved himself wisely,” we also see that, at times, he did not (2 Sam. 11). And so it is with us today. But there’s more.
The other is David’s psalms. It has been said that in 2 Samuel, we see David’s actions; but in the Psalms, we see his heart. That’s not to say that heart > actions; for such is positively NOT the case (cf. Matt. 7:21-23). Rather, David’s heart led him to confess and forsake his sin (cf. Psa. 32:3-5).
Perhaps “mess” is a bit harsh on David; for there is another word that accurately describes his “messiness”: human. The key to what made David “a man after God’s own heart” was his own heart; or, because of his good heart, David always took care of his sin, making it right with God (cf. Psa. 51).