Within the mind of a girl named Riley are the basic emotions that control her actions—Joy, Sadness, Fear, Disgust, and Anger. Her experiences become memories, stored as colored orbs, which are sent into long-term memory each night. Her five most important "core memories" power aspects of her personality which take the form of floating islands. Joy acts as the leader, and she and the rest of the emotions try to limit Sadness's influence.
At the age of 11, Riley moves to San Francisco for her father's new job. She at first has poor experiences; the new house is cramped and old, her father hardly has any time for her, a local pizza parlor only serves pizza topped with broccoli, and the moving van with their belongings ends up in Texas and will not arrive for weeks. On Riley's first day at her new school, Sadness retroactively turns joyous memories sad, which causes Riley to cry in front of her class and creates a sad core memory. Joy tries to dispose of it by using a vacuum tube but accidentally knocks the other core memories loose during a struggle with Sadness, disabling the personality islands. Joy, Sadness, and the core memories are sucked out of the Headquarters.
In Joy and Sadness's absence, Anger, Fear, and Disgust are left in control, with disastrous results, distancing Riley from her parents, friends, and hobbies. Because of this, her personality islands gradually crumble and fall into the "Memory Dump", where memories are forgotten. Finally, Anger inserts an idea into the console, prompting Riley to run away to Minnesota, believing it will restore her happiness.
While navigating the vast long-term memory area, Joy and Sadness encounter Bing Bong, Riley's childhood imaginary friend, who suggests riding the "train of thought" back to Headquarters. The three, after extreme inconvenience caused by the islands' dissolution, eventually catch the train but it halts when Riley falls asleep, then derails entirely with the collapse of another island.
In desperation, Joy abandons Sadness and tries to ride a "recall tube" back to the Headquarters but the ground below the tube collapses, breaking and sending Joy and Bing Bong plunging into the Memory Dump. A crestfallen Joy discovers a sad memory that turned happy when Riley's parents and friends comforted her. Joy finally understands Sadness's purpose: alerting others when Riley is emotionally overwhelmed and needs help. Joy and Bing Bong try to use Bing Bong's old wagon rocket to escape the Memory Dump but are unable to fly high enough due to Bing Bong's weight. On their last attempt, Bing Bong jumps out to allow Joy to escape as he fades away.