At the beginning of time, Sophia (the world soul) broke away from Christ (the world spirit) and gave birth to Yaldabaoth, the arrogant creator-god of the Old Testament.
The exact process by which this cosmic fiasco occurred was the subject of much debate among the gnostics; in perhaps the oldest version of the story, Sophia’s desire somehow veiled infinity, casting a murky shadow which congealed into a dark ocean set apart from the realm of light:
“A veil exists between the World Above and the realms that are below; and Shadow came into being beneath the veil; and that Shadow became Matter; and that Shadow was projected apart. And what she [Sophia] had created became a product in the Matter, like an aborted fetus.” 
The pool of darkness transformed into a yawning abyss of chaotic energy and began to produce terrible, half-formed mutants:
“[And] as for the shadow, the powers which came into being after [it] called it “the limitless Chaos.” And out of it every race of gods was brought forth, both one and the other and the whole place…”