Undertale is set in the Underground, a realm where monsters were banished after war broke out with humans. The Underground is sealed from the surface by a magic barrier with a singular gap at Mount Ebott. In the year 201X, a human child falls into the Underground from Mount Ebott and encounters Flowey, a sentient flower who teaches the player the game's mechanics and lies about "LV", or "LOVE", in an attempt to kill them. The human is rescued by Toriel, a motherly goat-like monster, who teaches them how to survive conflict in the Underground without killing. She intends to adopt the human, wanting to protect them from Asgore, the king of the Underground.
The human eventually leaves Toriel to search for Asgore's castle, which contains the barrier to the surface world. They encounter several monsters, such as the skeletons Sans and Papyrus, two brothers who act as sentries for the Snowdin forest; Undyne, the head of the royal guard; Alphys, the kingdom's royal scientist; and Mettaton, a robotic television host Alphys created. Most of the monsters are fought, with the human choosing whether to kill them or to spare and possibly befriend the monster. During their travels, the human learns that many years ago, Asriel, the son of Asgore and Toriel, befriended the first human who fell into the Underground. When the child abruptly died, Asriel used the child's soul to pass through the barrier, intending to return the body to the surface. The humans living there attacked and killed Asriel, causing Asgore to declare war. In the present day, Asgore has collected six souls from fallen humans, of which he needs one more to destroy the barrier.
The game's ending depends on how the player handles encounters with monsters. If the player completes a playthrough without killing any monsters (or killed some but not all of the monsters) they experience the "Neutral" ending. The human arrives at Asgore's castle and is forced to fight him. Sans stops the human before their confrontation, revealing that the human's "LOVE" and "EXP" are acronyms for "level of violence" and "execution points", respectively. Sans judges the human based on their accumulated "LOVE" and "EXP". The human then fights Asgore, but Flowey interrupts, killing Asgore and stealing the human souls. With the help of the souls, the human defeats Flowey and leaves the Underground. They then receive a phone call from Sans, detailing the state of the Underground after the human's departure, with the specifics depending on who was killed or spared.
If the player kills no monsters before completing a "Neutral" ending, they can reload their saved game to complete the "Pacifist" ending. Flowey is revealed to be a reincarnation of Asriel accidentally created by Alphys's experiments. During the fight with Asgore, Toriel stops the battle and is joined by the other monsters the human befriended. Flowey ambushes the group, absorbing the souls of all the humans and monsters in order to take an older Asriel's form. During the ensuing fight, the human manages to connect with the souls of their friends, and eventually defeats Asriel: He reverts to his child form, destroys the barrier, and expresses remorse for his actions before leaving, revealing the human's true name as Frisk. The human falls unconscious and is awoken to see their friends surrounding them. The monsters peacefully reintegrate with the humans, while the human has the option of accepting Toriel as their adoptive mother.
A third ending, known by fans as the "No Mercy" or "Genocide" ending, ensues if the player kills every single monster in the game that can be fought. This involves continuously triggering random encounters in each area until no more monsters remain. Going down this route changes many aspects of the game: the game's soundtrack becomes more ominous by playing at a lower speed and pitch, and most NPCs are absent from the Overworld as they evacuate to escape from the player's rampage. The few remaining characters that can be interacted with have changed dialogue, reflecting the impact the player's actions are having on the game's world. When the human reaches Asgore's castle, Sans attempts to stop them, but fails and is slain. Flowey kills Asgore in an attempt to obtain mercy, but is killed by the human. Chara, the first fallen child who befriended Asriel, then appears and erases the world. To enable further replays of the game, the player must give their soul to Chara, restoring the world and causing a permanent alteration to the Pacifist ending.
Official Undertale Wikipedia here