Yahweh Sent the demon
In 1 Samuel 16:14-23 there is the story of a tormenting spirit that Yahweh sent to Saul after He removed His Spirit from him. Even the servants around the palace knew somehow that Yahweh had sent the demon to torture the boss.
Tormenting Saul was not the point of sending the spirit, though. The point was giving David the throne. You can’t see either of those truths at the beginning of the story. That is important to notice with the advantage we have of knowing the end of the story.
The first impact Yahweh made with the missionary demon was drawing David into the palace. He was called in to play anointed music that drove the demon out of the palace. But Yahweh sent the demon, so it always came back.
Eventually, the demon drove David out of the palace, by influencing Saul to try to kill him. It accused him of evil. It drew on the resources of the throne to chase David with the hope of cutting him off from his destiny. It forced him to form an army. It forced him to serve other thrones. Finally, it caused Saul’s death.
David could not prevail against Saul because of the demon. He could not prevail permanently against the demon for two reasons: If he really overcame the demon, he would have to harm Saul, because of Saul’s alignment with the spirit. Second, Yahweh sent the demon.
David was destined by the call of Yahweh. He was strengthened by the fight with Saul to hate Saul’s ways enough to refuse to walk in them.
He did not quit expecting to sit on the throne, therefore, he did not fail.