A girl named Riley is born in Minnesota, and within her mind, five manifestations of her emotions—Joy, Sadness, Disgust, Fear and Anger—come to life. The emotions live in Headquarters, Riley's conscious mind, where they influence Riley's actions and memories via a control console. Her new memories are housed in colored orbs, which are sent into storage at the end of every waking period. The most important or "core" memories are housed in a hub in Headquarters and power five "islands", each of which reflects a different aspect of Riley's personality. Joy acts as the dominant emotion to keep Riley in a happy state, but she and the others do not understand Sadness's purpose.
When Riley is 11 years old, her family relocates to San Francisco after her father gets a new job. Joy becomes concerned when Sadness begins touching happy memories, causing them to turn sad, so she tries to keep Sadness isolated. However, on Riley's first day at her new school, Sadness accidentally causes Riley to cry in front of her class, creating a sad core memory. Joy attempts to dispose of the new core memory before it reaches the central hub, but she accidentally knocks the other core memories loose in her struggle with Sadness, shutting down the personality islands and making them unstable. Before Joy can put them back, she, Sadness, and the core memories are sucked out of Headquarters through the memory tube leading to the rest of Riley's mind. They end up in the labyrinthine storage area of Riley's long-term memories and set out to return to Headquarters.
Anger, Disgust, and Fear attempt to maintain Riley's emotional state in Joy's absence, but inadvertently distance Riley from her parents, friends, and hobbies, resulting in her personality islands slowly crumbling and falling into the Memory Dump, an abyss where faded memories are disposed and forgotten. Anger inserts an idea to run away to Minnesota into the control console, believing they can produce new happy core memories there. Meanwhile, Joy and Sadness find Bing Bong, Riley's childhood imaginary friend, who is desperate to reconnect with her. He tells them they can get to Headquarters by riding the train of thought. After exploring different areas of Riley's mind, the three eventually catch the train, but it derails when another personality island falls.
As Riley prepares to board a bus bound for Minnesota, Joy attempts to use a "recall tube" to return to Headquarters, but the last personality island falls and breaks the tube, sending Joy into the Memory Dump along with Bing Bong. While despairingly looking through old memories, Joy discovers a sad memory in Riley's life that becomes happy when her parents and friends come to comfort her over losing a hockey game, causing her to realize Sadness's true importance: alerting others when Riley needs help.
Joy and Bing Bong try to use Bing Bong's discarded wagon rocket to get out of the Memory Dump, but after several failed attempts, Bing Bong realizes their combined weight is too much and jumps out and fades away, allowing Joy to escape. Joy uses various tools from Imagination Land to propel herself and Sadness to Headquarters, where they find that Anger's idea has disabled the control console, rendering Riley depressed and apathetic. At Joy's urging, Sadness takes control and successfully removes the idea, reactivating the console and prompting Riley to return home.
As Sadness reinstalls the core memories, Riley arrives home and breaks down in tears, confessing to her parents that she misses her old life. As her parents comfort and reassure her, Joy and Sadness work together to create a new, amalgamated core memory that creates a new personality island. A year later, Riley has adapted to her new home, and all her emotions now work together to help her lead a content, more emotionally complex life as she ages, with an expanded control console and additional personality islands produced by new core memories comprising multiple emotions.