One day, a spirit comes before God (people generally quote it as Satan, but the original wording is more like Lawyer) and is dicussing how things are going, and God says

"Observe Job. He follows my ways, he's a great guy, etc., and thus I have blessed him."

And the lawyer says "But...he only follows you, to whatever degree he does, because you reward him for it.

And so, over a period, God kills Job's family, destroys his home, his wealth, etc.

And at the end, Job is left sitting on a heap of ash, mourning before God.

His wife and friends offer him a number of different advisements...curse God, ask God for forgiveness, etc.

The general consensus being that:

  1. Either God's just being malicious, and does mean things to nice people for the hell of it, in which case Job might as well just be smart for once and tell Him to fuck off,
  2. Or, more popularly, Job has to have done something wrong for him to be punished like this.

Job knows he hasn't done anything wrong. And he knows that God is just. So he basically sits there and gives rebuttal to his wife and friends, on this basis. This goes on for a while.

Then God comes by, and Job asks "Why?"

And God says "I've created everything here, I hold it all together...who are you to ask me why? You're part of the scheme of things, part of my creation. I am in control."

And Job says "Yeah, that's kind of what I figured".

And God restores his family and riches to an even higher level than they were previously, and the law is satisfied.

The generally lesson to be gained is that Bad things happen to Good people not because they did something wrong, but generally because, being good people, they come to the attention of the powers that be, and are tested.

This is not particularly comforting. But it does make rather a bit of sense.