1 Chronicles 21 gives us the same story...
1And Satan stood up against Israel, and provoked David to number Israel.
2And David said to Joab and to the rulers of the people, Go, number Israel from Beersheba even to Dan; and bring the number of them to me, that I may know it.
3And Joab answered, The LORD make his people an hundred times so many more as they be: but, my lord the king, are they not all my lord's servants? why then doth my lord require this thing? why will he be a cause of trespass to Israel?
4Nevertheless the king's word prevailed against Joab. Wherefore Joab departed, and went throughout all Israel, and came to Jerusalem.
5And Joab gave the sum of the number of the people unto David. And all they of Israel were a thousand thousand and an hundred thousand men that drew sword: and Judah was four hundred threescore and ten thousand men that drew sword.
6But Levi and Benjamin counted he not among them: for the king's word was abominable to Joab.
7And God was displeased with this thing; therefore he smote Israel.
8And David said unto God, I have sinned greatly, because I have done this thing: but now, I beseech thee, do away the iniquity of thy servant; for I have done very foolishly.
9And the LORD spake unto Gad, David's seer, saying,
10Go and tell David, saying, Thus saith the LORD, I offer thee three things: choose thee one of them, that I may do it unto thee.
11So Gad came to David, and said unto him, Thus saith the LORD, Choose thee
12Either three years' famine; or three months to be destroyed before thy foes, while that the sword of thine enemies overtaketh thee; or else three days the sword of the LORD, even the pestilence, in the land, and the angel of the LORD destroying throughout all the coasts of Israel. Now therefore advise thyself what word I shall bring again to him that sent me.
13And David said unto Gad, I am in a great strait: let me fall now into the hand of the LORD; for very great are his mercies: but let me not fall into the hand of man.
14So the LORD sent pestilence upon Israel: and there fell of Israel seventy thousand men.
15And God sent an angel unto Jerusalem to destroy it: and as he was destroying, the LORD beheld, and he repented him of the evil, and said to the angel that destroyed, It is enough, stay now thine hand. And the angel of the LORD stood by the threshingfloor of Ornan the Jebusite.
16And David lifted up his eyes, and saw the angel of the LORD stand between the earth and the heaven, having a drawn sword in his hand stretched out over Jerusalem. Then David and the elders of Israel, who were clothed in sackcloth, fell upon their faces.
17And David said unto God, Is it not I that commanded the people to be numbered? even I it is that have sinned and done evil indeed; but as for these sheep, what have they done? let thine hand, I pray thee, O LORD my God, be on me, and on my father's house; but not on thy people, that they should be plagued.
I believe it was the devil that actually tempted David to sin because
James 1:13-14 tells us that God does not tempt us. Each of us is drawn by our own lusts. However, I would venture to say that the Lord allowed satan to tempt David just like He (the Lord) allowed satan to tempt Job to curse God by afflicting Job. Job triumphed in his case. David sinned in his case, but the Lord was still merciful to David.
Oh Lord, indeed your mercy endureth toward all generations!!!