Job did indeed sin, in spite of the fact that God called him blameless and upright. How could both statements be true?
Job was blameless in virtually everything that he did. He was a model husband and father. He was generous with his wealth and his time in serving the people of his community. He obeyed God in every aspect of his life. Even his closest companions could not find a single real fault in his behavior, though his friends tried their best to imagine what he might have done. However, when God showed Job his sin, he repented—not just superficially, but with a depth of sincere sorrow and regret.
He explains his sin in his own words. In responding to God's questioning, he said: "You asked, 'Who is this who hides counsel without knowledge?' Therefore I have uttered what I did not understand, things too wonderful for me, which I did not know. [That is, Job, unaware at the time of the 'behind the scenes' activity between God and Satan, assumed all his problems were a result of God's discipline. He had stated that he had lived righteously before God and was undeserving of the treatment that God was bringing into his life, as if God was unjust in His treatment of him!] Listen, please, and let me speak; You said, 'I will question you, and you shall answer Me.' I have heard of You by the hearing of the ear, but now my eye sees You. Therefore I abhor myself, and repent in dust and ashes" (Job 42:3-6 Job 42:3-6  Who is he that hides counsel without knowledge? therefore have I uttered that I understood not; things too wonderful for me, which I knew not.
 Hear, I beseech you, and I will speak: I will demand of you, and declare you to me.
 I have heard of you by the hearing of the ear: but now my eye sees you.
 Why I abhor myself, and repent in dust and ashes.
American King James Version×).
In his suffering, Job had charged God with acting unjustly. He had pleaded for an opportunity to appear in court with Him. When God finally speaks, His comments are not what we would have expected Him to have said. God primarily speaks of the awesome acts of creation, the awesome creatures in it and His care for all that He has made. In doing so, He shows how little understanding Job has of the big picture. How could Job argue his case with God as an equal? If God is so attuned to His creation, how could He be unaware of Job's suffering? Job comes to perceive God in a way he never had before!
Part of what Job repented of was the capacity within himself, as brought forth in his trial, of being at odds with God. He may not have believed beforehand that he was capable of arguing with and questioning God's goodness and justice and wisdom. In the crucible of this trial, that capacity within himself was brought to the fore, and he said things about God that an enemy would say.
This greater self-realization led him to deep repentance. When he realized this about himself, he repented, not necessarily of what he had done, but of what he was—a being capable of becoming an enemy of God. In the end, he said that he abhored himself—that capacity in himself to believe evil about God. That is an important realization for anyone who will live under God's sovereignty for all eternity. By the end of the account, Job had made a conscious decision to live by faith in God's goodness, and to never question it again, regardless of any provocation or temptation to do so.
There are important lessons we can learn from the book of Job. We should realize that a person's trials are not always a result of his or her own mistakes or sins. They can come about from other sources or other reasons, and so we should not level false accusations as Job's friends did. We should also learn from Job's experience to maintain patient respect and trust in God even in the midst of our sufferings (James 5:10-11 James 5:10-11  Take, my brothers, the prophets, who have spoken in the name of the Lord, for an example of suffering affliction, and of patience.
 Behold, we count them happy which endure. You have heard of the patience of Job, and have seen the end of the Lord; that the Lord is very pitiful, and of tender mercy.
American King James Version×). Seeing God's greatness and our own insignificance can help us to have a realistic perspective and to learn whatever lessons we can from the experience.
For more insight, read our booklet The Road to Eternal Life.