A twist where it is revealed previous events in the story were just part of a character's dream, hallucination or some other escape from reality, often put at the end to reveal the entirety of the story was some sort of dream.
(https://tvtropes.org/pmwiki/pmwiki.php/Main/AllJustADream)