King David sinned by counting the Jews and the prophet Gad (through G-d’s command) offered him a choice of three punishments: three years of famine, three months of defeat at war, or three days of pestilence. King David chose the last one because he felt it was better to be in G-d’s hands than man’s hands. This is why we begin Tachanun with the statement “And David said to Gad, ‘I am greatly distressed, let me fall into the hands of G-d, for He is very merciful. Do not let me fall into the hands of man.”