The following excerpts from Peter Kreeft's book,
Fundamentals of the Faith, answers your question far better than anything I could write. Although it is from a Christian viewpoint, it still agrees with amman, as Christians, Muslims, and Jews all believe in the same God. And for your atheists out there - just because you don't believe in God doesn't mean he doesn't exist - because He certainly does!
The Problem of Evil:
There are four parts to the solution to the problem of evil. First, evil is not a thing, an entity, a being... No, evil is not a thing but a wrong choice, or the damage done by a wrong choice. Evil is no more a positive thing than blindness is. But it is just as real. It is not a thing, but it is not an illusion..
Second, the origin of evil is not the Creator but the creature's freely choosing sin and selfishness. Take away all sin and selfishness and you would have heaven on earth...
Furthermore, the cause of physical evil is spiritual evil. The cause of suffering is sin.
God is the source of all life and joy. Therefore, when the human soul rebels against God, it loses its life and joy. Now a human being is body as well as soul. We are single creatures, not double: we are not even body and soul as much as we are embodied soul, or ensouled body. So the body must share in the soul's inevitable punishment?-a punishment as natural and unavoidable as broken bones from jumping off a cliff or a sick stomach from eating rotten food rather than a punishment as artificial and external as a grade for a course or a slap on the hands for taking the cookies.
If the origin of evil is free will, and God is the origin of free will, isn't God then the origin of evil? Only as parents are the origin of the misdeeds their children commit by being the origin of their children. The all-powerful God gave us a share in his power to choose freely. Would we prefer he had not and had made us robots rather than human beings?
A third part of the solution to the problem of evil is the most important part: how to resolve the problem in practice, not just in theory; in life, not just in thought. Although evil is a serious problem for thought (for it seems to disprove the existence of God), it is even more of a problem in life (for it is the real exclusion of God). But even if you think the solution in thought is obscure and uncertain, the solution in practice is as strong and clear as the sun: it is the Son. God's solution to the problem of evil is his Son Jesus Christ. The Father's love sent his Son to die for us to defeat the power of evil in human nature: that's the heart of the Christian story. We do not worship a deistic God, an absentee landlord who ignores his slum; we worship a garbageman God who came right down into our worst garbage to clean it up. How do we get God off the hook for allowing evil? God is not off the hook; God is the hook. That's the point of a crucifix.
The Cross is God's part of the practical solution to evil. Our part, according to the same Gospel, is to repent, to believe, and to work with God in fighting evil by the power of love. The King has invaded; we are finishing the mop-up operation.
Finally, what about the philosophical problem? It is not logically contradictory to say an all-powerful and all-loving God tolerates so much evil when he could eradicate it? Why do bad things happen to good people? The question makes three questionable assumptions.
First, who's to say we are good people? The question should be not "Why do bad things happen to good people?" but "Why do good things happen to bad people?" If the fairy godmother tells Cinderella that she can wear her magic gown until midnight, the question should be not "Why not after midnight?" but "Why did I get to wear it at all?" The question is not why the glass of water is half empty but why it is half full, for all goodness is gift. The best people are the ones who are most reluctant to call themselves good people. Sinners think they are saints, but saints know they are Sinners. The best man who ever lived once said, "No one is good but God alone. "
Second, who's to say suffering is all bad? Life without it would produce spoiled brats and tyrants, not joyful saints... Suffering can work for the greater good of wisdom.
Third, who's to say we have to know all God's reasons? Who ever promised us all the answers? No wonder Socrates was declared by the Delphic oracle to be the wisest man in the world. He interpreted that declaration to mean that he alone knew that he did not have wisdom, and that was true wisdom for man.
God has let us know a lot. He has lifted the curtain on the problem of evil with Christ. There, the greatest evil that ever happened, both the greatest spiritual evil and the greatest physical evil, both the greatest sin (deicide) and the greatest suffering (perfect love hated and crucified), is revealed as his wise and loving plan to bring about the greatest good, the salvation of the world from sin and suffering eternally. There, the greatest injustice of all time is integrated into the plan of salvation that Saint Paul calls "the righteousness (Justice) of God". Love finds a way. Love is very tricky. But love needs to be trusted.
The worst aspect of the problem of evil is eternal evil, hell. Does hell not contradict a loving and omnipotent God? No, for hell is the consequence of free will. We freely choose hell for ourselves; God does not cast anyone into hell against his will. If a creature is really free to say yes or no to the Creator's offer of love and spiritual marriage, then it must be possible for the creature to say no. And that is what hell is, essentially. Free will, in turn, was created out of God's love. Therefore hell is a result of God's love. Everything is.
No sane person wants hell to exist. No sane person wants evil to exist. But hell is just evil eternalized. If there is evil and if there is eternity, there can be hell. If it is intellectually dishonest to disbelieve in evil just because it is shocking and uncomfortable, it is the same with hell. Reality has hard corners, surprises, and terrible dangers in it. We desperately need a true road map, not nice feelings, if we are to get home. It is true, as people often say, that "hell just feels unreal, impossible." Yes. So does Auschwitz. So does Calvary.
Source