Welcome back, Pixar.

It’s been at least five years since the last great Pixar film (or more, depending on your feelings about Toy Story 3). In the interim, the company cranked out a series of sequels — some quite entertaining, but few as transcendently beautiful as the original concepts that turned the studio into this century’s most dependable Hollywood brand. Their latest effort, Inside Out, isn’t just a return to form; it surpasses almost all of their previous classics. It is, from start to finish, one of Pixar’s best films.

Early scenes establish the premise: The mind of every living being contains a “Headquarters,” a command center piloted by the personifications of five different emotions, each fighting for control: Joy, Sadness, Fear, Anger, and Disgust. Inside Out focuses primarily on the brain of an ordinary 11-year-old girl named Riley (Kaitlyn Dias), who’s freshly transplanted from Minnesota to San Francisco with her Mom (Diane Lane) and Dad (Kyle MacLachlan). While Riley gets acclimated to her new surroundings a crisis begins to bubble inside her head: A fight between Joy (Amy Poehler), who is obsessed with keeping Riley perpetually happy, and Sadness (Phyllis Smith), who keeps accidentally tainting Riley’s lighthearted memories, gets out of control. In the ensuing scuffle, Joy and Sadness get sucked out of Headquarters and dumped in Riley’s long-term memory. While Fear (Bill Hader), Anger (Lewis Black), and Disgust (Mindy Kaling) struggle to keep Riley on track without their cohorts, Joy and Sadness must figure out how to get back home.

On its surface, Inside Out is yet another Pixar film — like Toy StoryRatatouille, and both of director Pete Docter’s previous efforts, Monsters Inc. and Up — about a couple of mismatched buddies learning to work together in the midst of a desperate quest. It looks like a typical kids movie; the animation is bright and colorful, and there’s plenty of slapstick comedy. But everything that happens in Riley’s head corresponds exactly to developments in her new life in San Francisco, which parallels Joy and Sadness’ journey but grows significantly darker, both visually and tonally. It’s these scenes that give Inside Out its real power, and turn Riley’s inner turmoil into an allegory for the painful but important process of growing up, and learning that sadness is sometimes an essential part of life.

Although early skeptics dismissed Inside Out as a shameless retread of the old ’90s sitcom Herman’s Head, Docter and co-director Ronnie del Carmen make the material their own with ingenious character and production design. In typical Pixar fashion, everything in this cranial ecosystem fits together ingeniously, from the creation and storage of memories, to the mechanics of the “Train of Thought,” to the strata of workers inside the brain (which include janitors who keep things orderly by discarding useless old memories like piano lessons and the names of the U.S. Presidents besides Washington and Lincoln). And the clever concepts never cease; Docter and del Carmen toss off ideas good enough to form the entire foundations of lesser movies (like “Dream Productions,” the cliché-driven film studio that controls Riley’s slumber-time entertainment).

Docter and del Carmen’s creation is fantastical but utterly convincing. For all its abstractions, it still reflects the real complexity and fragility of the human mind, which is so easy damaged by trauma or neglect. These are serious subjects for a children’s film — or any mainstream film in an era where viewers demand simplistic escapist entertainment and only the happiest of endings. Inside Out is about the danger of that approach to moviemaking — and that approach to life. Trying to insulate yourself from unhappiness, it warns, only leads to greater suffering down the road.

The film perfect embodies those values; as hilarious and thrilling as the early scenes are, they’re also another way to deflect or ignore tough emotions; Doctor and del Carmen initially sideline Sadness the same way Joy does. But as the storyline progresses, it leavens the action and humor with more and more melancholy, particularly in the form of Bing Bong (a terrific Richard Kind), Riley’s now-forgotten imaginary friend from childhood, who helps Joy and Sadness get back to Headquarters and helps the movie practice exactly what it preaches about heartache, grief, and healing.

After the overwhelmingly poignant opening of Up and the even-more-moving climax of Inside Out, there’s no question: Pete Docter is the undisputed king of making grown-ass adults cry at kids’ cartoons. No one working in film today better understands how to embrace sentimentality without succumbing to mawkishness. Docter doesn’t treat Riley’s inner world like a gimmick, either; Joy and Sadness’ journey to get home becomes a massive life-or-death struggle, the backbone of a movie that is funny and entertaining, but also tragic and heart-rending in ways rarely allowed in Hollywood. As the director of Monsters. Inc and Up, and the co-writer of Toy StoryToy Story 2, and WALL-E, he might be Pixar’s most unappreciated genius. At the very least, he’s returned a struggling studio to its former glory and produced a true masterpiece.

Additional Thoughts:

-Pixar’s attention to detail is second to none. Note, for example, the way the movie’s title appears onscreen just as Riley’s family exits a tunnel on their way to San Francisco. They were inside; now they’re out. Or the match cuts from the light bulbs inside Riley’s head (which represent ideas) to a light bulb over Riley’s shoulder in the real world. It’s subtle but brilliant stuff.

-Inside Out is an instant classic. The short that plays before it, “Lava,” is not. Don’t freak out if you’re late to the theater and miss the first couple minutes.