A heavenly Adversary arose against Israel and incited David to count Israel.
References for 1 Chronicles 21:1
So David told Joab and the leaders of the people, "Go throughout all the tribes of Israel, from Dan to Beer-sheba, and take a census of the people so I know how many people there are."
But Joab replied, "May the LORD increase his people a hundred times! Sir, aren't you the king, and aren't they all your servants? Why do you want to do this? Why bring guilt on Israel?"
But the king overruled Joab, who left and traveled throughout all Israel. When he returned to Jerusalem,
he reported to David the total number: there were 1,100,000 men available for military service in all Israel, while Judah alone had 470,000.
He didn't include Levi and Benjamin among them, because Joab disagreed with the king's order.
God was offended by this census and punished Israel.
Then David said to God, "I have sinned greatly in what I have done! Now please take away the guilt of your servant because I have done something very foolish."
The LORD told Gad, David's seer:
Go and tell David, This is what the LORD says: I'm offering you three punishments. Choose one of them, and that is what I will do to you.
When Gad came to David, he said to him, "This is what the LORD says: Take your choice:
three years of famine, three months of fleeing from your enemies while your enemies' sword overtakes you, or three days of the LORD's sword, that is, plague in the land and the LORD's messenger bringing disaster in every part of Israel. Decide now what answer I should take back to the one who sent me."
References for 1 Chronicles 21:12
"I'm in deep trouble," David said to Gad. "I'd rather fall into the hands of the LORD, who is very merciful; don't let me fall into human hands."
So the LORD sent a plague throughout Israel, and seventy thousand Israelites fell dead.
Then God sent a messenger to Jerusalem to destroy it. But just as the messenger was about to destroy it, the LORD looked and changed his mind about the destruction. He said to the messenger who was destroying it, "That's enough! Withdraw your hand!" At that time the LORD's messenger was standing near the threshing floor of Ornan the Jebusite.
When David looked up, he saw the LORD's messenger stationed between the earth and the sky with a drawn sword in his hand stretched out against Jerusalem. Then David and the elders, dressed in mourning clothes, fell on their faces;
and David said to God, "Wasn't it I who ordered the numbering of the people? I'm the sinner, the one responsible for this evil. But these sheep—what have they done? LORD, my God, turn your hand against me and my household, but spare your people from the plague."
The LORD's messenger ordered Gad to tell David that he should go up to the threshing floor of Ornan the Jebusite in order to set up an altar for the LORD.
So David went up, following the instructions Gad had delivered in the LORD's name.
Ornan turned around and saw the king. His four sons who were with him hid themselves, but Ornan continued threshing wheat.
References for 1 Chronicles 21:20
When David approached Ornan, Ornan looked up, recognized David, left the threshing floor, and bowed to David with his face to the ground.
David said to Ornan, "Give me the site of the threshing floor, charging me full price, so that I may build an altar to the LORD, and the plague among the people may come to an end."
Ornan replied to David, "Take it for yourself, and may my master the king do what he thinks is best. I'll even provide the oxen for the entirely burned offerings, the threshing boards for wood, and the wheat for the grain offering—I'll provide everything!"
But King David said to Ornan, "No, I will buy them from you at a fair price. I won't offer to the LORD what belongs to you nor offer an entirely burned offering that costs me nothing."
Then David gave Ornan six hundred shekels of gold by weight for the site.
David built an altar there for the LORD and offered entirely burned offerings and well-being sacrifices. He called on the LORD, who answered him with fire from heaven on the altar of the entirely burned offering, consuming the entirely burned offering.
References for 1 Chronicles 21:26
Then the LORD commanded the messenger to return his sword to its sheath.
At that time, after David saw that the LORD had answered him at the threshing floor of Ornan the Jebusite, he offered sacrifices there.
References for 1 Chronicles 21:28
The LORD's dwelling that Moses had made in the desert and the altar for entirely burned offerings were then at the shrine in Gibeon,
but David couldn't go there to seek God because he feared the sword of the LORD's messenger.