9 And, we are told, when death came upon the people, on the very first day at dinner time, when David saw the angel smiting the people, he said: “I have sinned, and I, the shepherd, have done wickedly, and this flock, what has it done? Let Your hand be upon me, and upon my father's house.” And so it repented the Lord, and He commanded the angel to spare the people, and David to offer a sacrifice, for sacrifices were then offered for sins; sacrifices are now those of penitence. And so by that humbling of himself he became more acceptable to God, for it is no matter of wonder that a man should sin, but this is reprehensible, if he does not recognize that he has erred, and humble himself before God.
Source: Letters (New Advent)