Joy and Sadness encounter Bing Bong, Riley's childhood imaginary friend, who suggests riding the train of thought back to Headquarters. The three eventually catch the train, but it is derailed when the "Honesty Island" collapses (when Riley steals her mother's credit card and begins to run away). In desperation, Joy abandons Sadness and tries to ride a "recall tube" back to Headquarters, but the last personality island collapses, breaking the tube, plunging Joy and Bing Bong into the Memory Dump. At the bottom, Joy then begins to lose hope, but discovers a sad memory of a hockey game that becomes happy when Riley's parents and friends comfort her. Joy realizes that Sadness serves an important purpose: to create empathy in 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 after several tries, Bing Bong realizes their combined weight is too much and jumps out, sacrificing himself to allow Joy to escape. Joy reunites with a despondent Sadness and manages to get them to Headquarters, only to discover that Anger's idea has disabled the console, rendering Riley apathetic. To the surprise of the others, Joy hands control of the console to Sadness, who is able to successfully extract the idea, reactivating the console and prompting Riley to return home.
As Sadness reinstalls the core memories, turning them sad, Riley arrives home to her parents and breaks down in tears, confessing that she misses her childhood in Minnesota. As her parents comfort her, Joy and Sadness work the console together, creating a new core memory that combines their emotions; a new island forms representing Riley's acceptance of her new life in San Francisco. A year later, Riley has adapted to her new home, made new friends, returned to her old hobbies, and adopted a few new ones (fueled by new, more nuanced core memories from combinations of her emotions). Inside Headquarters, her emotions all work together on a new expanded console with room for them all, enabling Riley to lead a more emotionally complex life.