The universe as it is known is actually bubble of time and order in a maelstrom of primal energies that could destroy mortal life in a blink. This bubble was blown by an alliance of titans and Eldritch beings which sought reprieve from the constant turmoil of the outside where any being more powerful could unmake anything or anyone as they wished. The alliance was actually the creation of the concept of trust outside the self and from that alliance a ritual of power between an Eldritch god and a century of titans. The god was the source of raw power while the titans worked together to perform the ritual while an ascendant titan prodigy created the entire concept at once as a single image and spun off bits to his brethren to offload detailed work while he moved on to mechanics, souls, power, energy, matter and rules that make existence possible.
The titans lived for millennial creating the original elves to watch the barrier. They fell out and many were imprisoned including the prodigal creator himself. In the strife and warfare that followed some of their servants rebelled and the mortal races were created and ignored as their masters fought or were imprisoned. For even they could not kill one another without destroying the ritual that protected them all. In the time of neglect heroes rose among the mortals and these heroes became gods and these gods were used as tools in the wars between titans until the mortal gods knew enough to turn on the titans themselves and in the titan god war much was destroyed.
The mortals won but the titans were only separated and imprisoned. The gods grew over time and the mortal races prospered under the kinder guidance of those ascended form among them. The mortals raised inside the creation being more attuned to its nature than the titans who had existed for timeless eons before creation was created.
Many waves of mortal gods came and went until at one fell swoop all mortal gods died off in a sudden catastrophe that has left echos until this day with reality careened but with no hand on the tiller to guide its passage. Following the loss of gods there was a long period where magic itself faded and was gone for several generations. Many magical races lost their identity and were absorbed by the masses of humanity.
Then magic returned abruptly but as a raging torrent of destructive energy. Knowledge of how to control magic had been lost and latent talents that revealed themselves in new dangerous ways. Over decades control was relearned and lost knowledge was reclaimed. Magical races returned and eventually so did the gods. But much knowledge was still lost.