There are many answers to this theodicy question, not one of which I have found satisfying.
I think the best option is to simply reject the idea of an omniscient, omnipotent, benevolent creator deity. Between that absurdity and atheism there are some plausible alternatives:
Polytheism: There are many gods, so good, some bad, most are indifferent. The good ones can prevent evil some of the time but not all of the time for the simple reason that their power is finite and they cannot be everywhere at once. This is what most people believed until Christianity and Islam came along.
Dualism: There is a good God of light, love, and life who created the cosmos and gave it life. Unfortunately, there is an equally potent god of darknessn malevolence, and destruction who lives for the sole purpose of destroying or defacing the creator's work. Historical examples of this system include Zoroastrianism and Manichaeism.
Platonism: The world is imperfect because its creator is, at best, a flawed, incompetent architect who botched it. Everything here is an imperfect copy of a perfect archetype or idea. There is a better world and a superior God (or gods) outside of this universe but he isn't going to rescue us. What we have to do is improve ourselves by purifying our souls of evil and earthly desires while contemplating exalted subjects like philosophy and mathematics and living an ethical life. The idea seems to originate with Socrates who passed it on to Plato and then to the neo-platonists like Plotinus and Iamblichus. Eventually the gnostics got a hold of it and identified the (now evil) creator god with Jehovah.