2 Samuel 15:31

And one told David, saying, Ahithophel is among the conspirators with Absalom. And David said, O LORD, I pray thee, turn the counsel of Ahithophel into foolishness.

Before the report came, David had already sent the ark back to the city in submission to whatever God should decide. He had left Zadok and Abiathar in place with Ahimaaz and Jonathan to learn the movements and purposes of the rebels and to send word to him secretly in the wilderness. The news that Ahithophel was among the conspirators with Absalom reached him during his mourning flight up the ascent of Olivet. He went barefoot with his head covered and weeping, while all the people with him covered their heads and wept as they went. Ahithophel was the ablest and most wily of political leaders, and his defection to Absalom was prompted by revenge for the family disgrace involved in David's wrong to Bathsheba, who was his granddaughter. Hearing that Ahithophel had joined the conspiracy forced David again to recognize his calamities as the results of his own sin.

David responded by praying for God to turn the counsel of Ahithophel into foolishness. The prayer was answered when Hushai, a wise and faithful counselor, arrived. David recognized that Hushai could serve him in Absalom's councils. He sent him back to Jerusalem to defeat Ahithophel's plans.