This paper develops an economic model to study the philosophical problem of evil. God's creation of the world is modeled as a problem of optimal incentives. A principal (God) must choose a world so that the populating agents behave according to his benevolent objective. In a world, the physical environment resembles a contract that determines the rewards and punishments for different choices. The agents' behavioral rule determines how they respond to these incentives. I characterize a contract and a behavioral rule that solve the principal's problem, and evil is evidenced. Specifically, evil endogenously aligns the agents' actions with the principal's objective. Other insights on the origin, cause, and role of evil are also derived from the model. The result of this analysis is a theodicy arisen from an economic model. As a byproduct, this paper shows how an economic model can be used to study philosophical or theological questions.