David, near death, tells Solomon to be strong and to keep the Lord's commands, walking in his ways and obeying his law, so that he may prosper in all he does and God's promise about his descendants may stand. He also leaves unfinished business: Joab must not die in peace for killing Abner and Amasa, the sons of Barzillai of Gilead are to eat at the king's table, and Shimei, who cursed David, must not go unpunished. David dies and is buried in the city of David, and the text notes that he reigned forty years, seven in Hebron and thirty-three in Jerusalem.
Adonijah goes to Bathsheba and asks her to plead with Solomon to give him Abishag as his wife. Bathsheba brings the request, but Solomon sees that Adonijah is again reaching for the throne and orders Benaiah to kill him. He then banishes Abiathar to Anathoth, fulfilling what was said about the house of Eli. When Joab hears this, he flees to the tent of the Lord and grasps the horns of the altar, but Benaiah kills him there at Solomon's command.
Finally Solomon orders Shimei to live in Jerusalem and forbids him to cross the Kidron Valley on pain of death. Shimei agrees, but three years later he goes to Gath to recover two runaway slaves. Solomon summons him back and Benaiah puts him to death. So the kingdom was established in Solomon's hand.