David committed adultery with Bathsheba.
Bathsheba was the wife of Uriah, one of David's trusted soldiers. While Uriah was away at war, David saw Bathsheba bathing on a rooftop and was attracted to her. He sent for her, slept with her, and she became pregnant. David then tried to cover up his sin by bringing Uriah back from the war and encouraging him to go home to his wife. However, Uriah refused to go home and instead slept at the palace gates. David then ordered Uriah to be placed in the front line of battle where he was killed. After Uriah's death, David married Bathsheba.