Narrative
God is angered when Saul, Israel's king, unlawfully offers a sacrifice and later disobeys a divine command both to kill all of the Amalekites and to destroy their confiscated property. Consequently, God sends the prophet Samuel to anoint a shepherd, David, the youngest son of Jesse of Bethlehem, to be king instead.
After God sends an evil spirit to torment Saul, his servants recommend that he send for a man skilled in playing the lyre. A servant proposes David, whom the servant describes as "skillful in playing, a man of valor, a warrior, prudent in speech, and a man of good presence; and the Lord is with him." David enters Saul's service as one of the royal armour-bearers and plays the lyre to soothe the king.
War comes between Israel and the Philistines, and the giant Goliath challenges the Israelites to send out a champion to face him in single combat. David, sent by his father to bring provisions to his brothers serving in Saul's army, declares that he can defeat Goliath. Refusing the king's offer of the royal armour, he kills Goliath with his sling. Saul inquires the name of the young hero's father.
Saul sets David over his army. All Israel loves David, but his popularity causes Saul to fear him ("What else can he wish but the kingdom?"). Saul plots his death, but Saul's son Jonathan, who loves David, warns him of his father's schemes and David flees. He goes first to Nob, where he is fed by the priest Ahimelech and given Goliath's sword, and then to Gath, the Philistine city of Goliath, intending to seek refuge with King Achish there. Achish's servants or officials question his loyalty, and David sees that he is in danger there. He goes next to the cave of Adullam, where his family joins him. From there he goes to seek refuge with the king of Moab, but the prophet Gad advises him to leave and he goes to the Forest of Hereth, and then to Keilah, where he is involved in a further battle with the Philistines. Saul plans to besiege Keilah so that he can capture David, so David leaves the city to protect its inhabitants. From there he takes refuge in the mountainous Wilderness of Ziph.
Jonathan meets with David again and confirms his loyalty to David as the future king. After the people of Ziph notify Saul that David is taking refuge in their territory, Saul seeks confirmation and plans to capture David in the Wilderness of Maon, but his attention is diverted by a renewed Philistine invasion and David is able to secure some respite at Ein Gedi. Returning from battle with the Philistines, Saul heads to Ein Gedi in pursuit of David. Needing privacy "to attend to his needs", Saul enters the cave where, as it happens, David and his supporters are hiding. David realizes he has an opportunity to kill Saul, but instead, he secretly cuts off a piece of Saul's robe. When Saul leaves the cave, David comes out to pay homage to the king, and to demonstrate using the piece of robe that he holds no malice towards him. The two are thus reconciled and Saul recognizes David as his successor.
A similar passage occurs in 1 Sam 26, when David is able to infiltrate Saul's camp on the hill of Hachilah and remove his spear and a jug of water from his side while he and his guards lie asleep. In this account, David is advised by Abishai that this is his opportunity to kill Saul, but David declines, saying he will not "stretch out [his] hand against the Lord's anointed". In the morning, David once again demonstrates to Saul that, despite ample opportunity, he did not deign to harm him. Saul, despite having already reconciled with David, confesses that he has been wrong to pursue David, and blesses him.
In 1 Samuel 27:1–4, David begins to doubt Saul's sincerity, and reasons that the king will eventually make another attempt on his life. David appeals to king Achish of Gath to grant him and his family sanctuary. Achish agrees, and upon hearing that David has fled to Philistia, Saul ceases to pursue him, though no such pursuit seemed to be in progress at the time. Achish permits David to reside in Ziklag, close to the border between Philistia and Judah. To further ingratiate himself to Achish and the Philistines, David and his men raid the Geshurites, the Girzites, and the Amalekites, but lead the royal court to believe they are attacking the Israelites, the Jerahmeelites, and the Kenites. While Achish comes to believe that David had become a loyal vassal, the princes (or lords) of Gath remain unconvinced, and at their request, Achish instructs David to remain behind to guard the camp when the Philistines march against Saul. David returns to Ziklag and saves his wives and the citizens from an Amalekite raid. Jonathan and Saul are killed in battle with the Philistines, and after hearing of their deaths, David travels to Hebron, where he is anointed king over Judah. In the north, Saul's son Ish-Bosheth is anointed king of Israel, and war ensues until Ish-Bosheth is murdered.
With the death of Saul's son, the elders of Israel come to Hebron and David is anointed king over all of Israel. He conquers Jerusalem, previously a Jebusite stronghold, and makes it his capital. He brings the Ark of the Covenant to the city, intending to build a temple for God, but the prophet Nathan forbids it, prophesying that the temple would be built by one of David's sons. Nathan also prophesies that God has made a covenant with the house of David stating, "your throne shall be established forever". David wins additional victories over the Philistines, Moabites, Edomites, Amalekites, Ammonites and king Hadadezer of Aram-Zobah, after which they become tributaries. His fame increases as a result, earning the praise of figures like King Toi of Hamath, Hadadezer's rival.
During a siege of the Ammonite capital of Rabbah, David remains in Jerusalem. He spies a woman, Bathsheba, bathing and summons her; she becomes pregnant. The text in the Bible does not explicitly state whether Bathsheba consented to sex with David. David calls her husband, Uriah the Hittite, back from the battle to rest, hoping that he will go home to have sex with his wife and the child will be presumed to be his. Uriah does not visit his wife, however, so David conspires to have him killed in the heat of battle. David then marries the widowed Bathsheba.
In response, Nathan, after trapping the king in his guilt with a parable that actually described his sin in analogy, prophesies the punishment that will fall upon him, stating "the sword shall never depart from your house." When David acknowledges that he has sinned, Nathan advises him that his sin is forgiven and he will not die, but the child will.
In fulfilment of Nathan's words, the child born of the union between David and Bathsheba dies, and another of David's sons, Absalom, fuelled by vengeance and lust for power, rebels. Thanks to Hushai, a friend of David who was ordered to infiltrate Absalom's court to successfully sabotage his plans, Absalom's forces are routed at the battle of the Wood of Ephraim, and he is caught by his long hair in the branches of a tree where, contrary to David's order, he is killed by Joab, the commander of David's army. David laments the death of his favourite son: "O my son Absalom, my son, my son Absalom! Would I had died instead of you, O Absalom, my son, my son!" until Joab persuades him to recover from "the extravagance of his grief" and to fulfill his duty to his people. David returns to Gilgal and is escorted across the River Jordan and back to Jerusalem by the tribes of Judah and Benjamin.
When David is old and bedridden, Adonijah, his eldest surviving son and natural heir, declares himself king. Bathsheba and Nathan go to David and obtain his agreement to crown Bathsheba's son Solomon as king, according to David's earlier promise, and the revolt of Adonijah is put down. David dies at the age of 70 after reigning for 40 years, and on his deathbed counsels Solomon to walk in the ways of God and to take revenge on his enemies.