The Book of Job is the 18th book of the Old Testament of the Bible, and contains a single story of a man named Job (prounounced "Jobe"). In the story, Job, a faithful servant of God, has his life turned upside down and his family killed because of a bet that God makes with Satan.
Job, who lives in the land of Uz, is "perfect and upright". (Job 1:1 ) He has a happy marriage with many sons and daughters, and he owns plenty of livestock and servants.
God meets Satan and asks: "Have you considered my servant Job? There is no one on earth like him; he is blameless and upright, a man who fears God and shuns evil." (Job 1:8 ) Satan replies that Job is good only because he has a good life, "stretch out your hand and strike everything he has, and he will surely curse you to your face."
God agrees to this wager, and gives Satan complete power over Job's life. First Satan kills Job's servants and livestock (Job 1:14-17). Then he kills Job's sons and daughters (Job 1:18-19 ). Job himself is afflicted with terrible boils over his entire body (Job 2:7-8 ). Yet Job does not renounce God, even though his wife tells him that he should. He does, however, complain a lot about his situation.
Although his neighbors also urge him to renounce God, Job remains loyal. He spends many chapters arguing with these neighbors. He tries to rationalize his situation but also asks God what he did to deserve his terrible fate. He initially receives no answer.
Finally God appears to Job to respond to his pleas. God essentially goes on a long tirade, not answering Job's questions, but instead repeatedly making comments like this: "Where wast thou when I laid the foundations of the earth? declare, if thou hast understanding." (Job 38:4 ) "Hast thou perceived the breadth of the earth? declare if thou knowest it all." (Job 38:18 ) "Knowest thou the ordinances of heaven? canst thou set the dominion thereof in the earth?" (Job 38:33 ) And so forth.
Job is chastened. He humbly replies: "Behold, I am vile; what shall I answer thee? I will lay mine hand upon my mouth. Once have I spoken; but I will not answer: yea, twice; but I will proceed no further." (Job 40:4-5 ) God then proceeds to brag about his accomplishments, and Job continues to be sorry for questioning him.
So God wins his bet with Satan, and he rewards Job by giving him more than he had before. Job receives more livestock, more servants, and bears more sons and daughters than he had before. Job lives to be 140 years old and dies happy.
The moral of this story is that we cannot understand God's motives, but if we trust in God unquestioningly, then he will provide for us.
God never did explain his reasons to Job, but the real reason why he dealt out all this punishment, misery, and the deaths of Job's innocent children and servants, was to settle a bet. That strikes some atheists as extremely petty.
And speaking of the children and servants, why get them involved? They were not even directly related to the bet. What did they do to deserve death? No doubt Job found consolation in his new family, but that is not much comfort to the dead family.