-Gaster in the Depths decides to try and create a new world.
-Preferring not to control it himself, he creates a sentient daemon program (WYRD) to do this instead.
-WYRD believes free will is flawed and creates a world like a game where it ultimately predetermines everyones' destiny.
-Gaster doesn't like this, so seals WYRD away, creating a new world run by himself on top of WYRD's, thus creating the Dark and Light Worlds. Gaster bases this new world off of Undertale's where he came from, but placing monsters on the surface as they desired.
-Years later Kris, Asriel, Dess, and Noelle are creating a roleplaying game and one night decide to play in the creepy fallout shelter.
-Kris with their interest in occult magic inadvertently breaks the seal holding WYRD. Dess is swapped for it, being placed in the UNUSED code, and WYRD begins to possess Kris as a vessel but only actively controls Kris at night.
-WYRD creates the prophecy, basing it off of the game the kids were playing, as part of a complicated scheme to force Kris into absorbing willpower via sealing dark fountains. Once Kris's body holds enough, WYRD can take possession of them permanently and simultaneously overpower Gaster, seizing control of both worlds.
-WYRD is the game's narrator.
-Gaster is able to reset the timeframe the game takes place preventing WYRD from taking power.
-Gaster decides to bring the player in as a random variable to possibly find a way to defeat WYRD, but WYRD places the player in Kris to ensure the fountains are still being absorbed by them.
-WYRD also believes they might be able to manipulate the player into giving them control by giving us a sense of power over others, thus the existence of the "weird route".
-There is a secret "true ending" which involves Susie teaming up with the player soul to become Susiezilla, defeat WYRD, and thus save Kris and all of Hometown.
TL;DR: Kris years ago accidentally released a demon that wants to turn the world into a videogame, and now we have to somehow stop it while we and the demon are controlling the same person. Also it's causing a timeloop.