Satan stood up against Israel and incited David to count [the people of] Israel.
References for 1 Chronicles 21:1
So David said to Joab and the commanders of the troops, "Go and count Israel from Beer-sheba to Dan and bring [a report] to me so I can know their number."
Joab replied, "May the Lord multiply the number of His people a hundred times over! My lord the king, aren't they all my lord's servants? Why does my lord want to do this? Why should he bring guilt on Israel?"
Yet the king's order prevailed over Joab. So Joab left and traveled throughout Israel and then returned to Jerusalem.
Joab gave David the total of the registration of the troops. In all Israel there were 1,100,000 swordsmen and in Judah itself 470,000 swordsmen.
But he did not include Levi and Benjamin in the count because the king's command was detestable to him.
This command was also evil in God's sight, so He afflicted Israel.
David said to God, "I have sinned greatly because I have done this thing. Now, because I've been very foolish, please take away Your servant's guilt."
References for 1 Chronicles 21:8
Then the Lord instructed Gad, David's seer,
References for 1 Chronicles 21:9
"Go and say to David, 'This is what the Lord says: I am offering you three [choices]. Choose one of them for yourself, and I will do it to you.' "
So Gad went to David and said to him, "This is what the Lord says: 'Take your [choice]-
either three years of famine, three months of devastation by your foes with the sword of your enemy overtaking you, or three days of the sword of the Lord-a plague on the land, the angel of the Lord bringing destruction to the whole territory of Israel.' Now decide what answer I should take back to the One who sent me."
David answered Gad, "I have great anxiety. Please, let me fall into the Lord's hands because His mercies are very great, but don't let me fall into human hands."
So the Lord sent a plague on Israel, and 70,000 Israelite men died.
Then God sent an angel to Jerusalem to destroy it, but when the angel was about to destroy the city, the Lord looked, relented concerning the destruction, and said to the angel who was destroying [the people], "Enough, withdraw your hand now!" The angel of the Lord was then standing at the threshing floor of Ornan the Jebusite.
References for 1 Chronicles 21:15
When David looked up and saw the angel of the Lord standing between earth and heaven, with his drawn sword in his hand stretched out over Jerusalem, David and the elders, clothed in sackcloth, fell down with their faces [to the ground].
David said to God, "Wasn't I the one who gave the order to count the people? I am the one who has sinned and acted very wickedly. But these sheep, what have they done? My Lord God, please let Your hand be against me and against my father's family, but don't let the plague be against Your people."
So the angel of the Lord ordered Gad to tell David to go and set up an altar to the Lord on the threshing floor of Ornan the Jebusite.
References for 1 Chronicles 21:18
David went up at Gad's command spoken in the name of the Lord.
Ornan was threshing wheat when he turned and saw the angel. His four sons, who were with him, hid themselves.
David came to Ornan, and when Ornan looked and saw David, he left the threshing floor and bowed to David with his face to the ground.
Then David said to Ornan, "Give me this threshing-floor plot so that I may build an altar to the Lord on it. Give it to me for the full price, so the plague on the people may be halted."
Ornan said to David, "Take it! My lord the king may do whatever he wants. See, I give the oxen for the burnt offerings, the threshing sledges for the wood, and the wheat for the grain offering-I give it all."
References for 1 Chronicles 21:23
King David answered Ornan, "No, I insist on paying the full price, for I will not take for the Lord what belongs to you or offer burnt offerings that cost [me] nothing."
So David gave Ornan 15 pounds of gold for the plot.
References for 1 Chronicles 21:25
He built an altar to the Lord there and offered burnt offerings and fellowship offerings. He called on the Lord, and He answered him with fire from heaven on the altar of burnt offering.
Then the Lord spoke to the angel, and he put his sword back into its sheath.
At that time, when David saw that the Lord answered him at the threshing floor of Ornan the Jebusite, he offered sacrifices there.
At that time the tabernacle of the Lord, which Moses made in the desert, and the altar of burnt offering were at the high place in Gibeon,
but David could not go before it to inquire of God, because he was terrified of the sword of the Lord's angel.