The film opens with a montage of a happy family through the years. Young Bea (Audrey Hoffman) is seen having fun with her parents (John Krasinski and Catharine Daddario), up until the mother begins to suffer from cancer. While she keeps on a happy face for Bea and continues to play with her, the mother eventually passes away.
Bea (Cailey Fleming), now 12, moves in with her grandmother Margaret (Fiona Shaw) since her father is going in for heart surgery. He continues to act goofy and create fake friends to keep Bea’s spirits up, but she doesn’t let on that she is not amused. While visiting her father, Bea befriends a boy named Benjamin (Alan Kim), who constantly gets himself injured and is seen playing with knight and dragon toys.
At night, Bea goes out to buy a charger for her mother’s old camcorder but sees an unusual-looking creature. When Bea calls out to her, assuming it’s another child, the creature reacts with surprise that Bea can see her. She runs into the building, and Bea follows her upstairs. She hears the creature’s voice behind another door, talking to a man named Cal (Ryan Reynolds), who lives in the floor above Margaret. Although Bea tries to talk to the creature, Cal insists there is nobody there.
The next night, Bea sees Cal walking with the creature before they go into another apartment. Bea watches as Cal climbs into the bedroom of a little girl, as he is trying to reach Blue (Steve Carell), a dim-witted but friendly giant, furry, purple imaginary friend, or IF. Blue was hoping for the little girl to be his new kid, but she cannot see him. When Cal tries to get Blue out, he ends up letting out a huge sneeze that wakes the little girl up, so Cal hides under her bed. He sneaks out of the room and finds Bea looking at him. As she starts to turn away in a panic, she is met by the female creature, an inkblot-style bug-like IF named Blossom (Phoebe Waller-Bridge). When Blossom tries to introduce herself, Bea faints.
Bea wakes up in Cal’s apartment with Blue and Blossom. Blossom explains to Bea that they are imaginary friends and that they are in the process of coming up with a matchmaking agency to help the other IFs find new kids, or else they will disappear due to being forgotten. While Bea is a little freaked out, she agrees to help them out.
The following day, Bea goes to visit her father in the hospital, only for Blue to be walking around the place. Bea tries to get him out of there, as she knows people will look at her funny if they see her talking to someone that isn’t visible to anyone else.
Later, Bea joins Cal at a hidden spot in Coney Island, where the IFs live in a retirement home, of sorts. After entering through a secret passage, Bea encounters a number of IFs. She walks in on a support group for IFs getting over their kids growing up, led by a sunflower IF called Flower (Matt Damon). There is also a superhero pup, Guardian Dog (Sam Rockwell), a blubbering blob called Slime (Keegan-Michael Key), an anxious Bubble (Awkwafina), a smarmy cup of water named Ice (Bradley Cooper), a dry-witted Robot (Jon Stewart), a Magician Mouse (Sebastian Maniscalco), and a trenchcoat detective IF called Cosmo (Christopher Meloni). Cal bumps into Art Teacher (Richard Jenkins), who recognizes Bea and tells Cal to find Lewis (Louis Gossett, Jr), a wise and elderly teddy bear IF that also remembers Bea by her full name, Elizabeth. Cal ends up falling between realms inside the retirement home, like in one of Art Teacher’s paintings before he and Bea end up in a Tina Turner musical performance with the other IFs.
While Bea is confused by the world around her, Lewis sits down with her and tells her to close her eyes, and all the memories will come flooding back to her. Bea does so and sees Coney Island full of both humans and IFs going all around the place. This encourages Bea to begin helping the IFs.
Bea wants to start by finding an IF for Benjamin. They do a round of interviews with Lewis, meeting other IFs like Uni the cheerful unicorn (Emily Blunt), an astronaut called Spaceman (George Clooney), a farting Gummy Bear (Amy Schumer), a cat in a onesie called Octokitty (Blake Lively), a Ghost (Matthew Rhys), Ally the alligator (Maya Rudolph), and a melting Marshmallow Man (also John Krasinski). Ultimately, none of them, including Blue, are able to appear visible to Benjamin.
At home, Bea looks through Margaret’s old belongings and finds out she used to be a dancer. To her surprise, she finds Blossom in one of the pictures, meaning she used to be Margaret’s IF. When Bea tries to get Blossom to try and reach out to Margaret, Blossom seems worried. Bea then puts on one of Margaret’s old records and wakes her up at night. Margaret ends up dancing once again, and this causes Blossom to not only dance alongside her, but she glows and grows butterfly wings since Margaret now remembers her.
Cosmo provides help by bringing Bea and Cal a file on Jeremy (Bobby Moynihan), Blue’s former child, now grown into an anxious adult. The three follow Jeremy to his job, where Blue makes a feeble attempt to get Jeremy to remember him, but he just lets out another powerful sneeze and causes Jeremy to tumble over and spill his coffee on himself. When Jeremy is about to go to a meeting, looking like a nervous mess, Blue puts his hand on Jeremy’s shoulder, and it causes Blue to glow like Blossom did since Jeremy now appears to remember Blue. He then goes in for his meeting less afraid.
When Bea returns home, she finds Margaret looking worried and telling her that her father had a health scare at the hospital. Bea rushes there, where all the other IFs are there for her. Her father is unconscious after an apparent complication from the surgery. Bea tearfully tells him a story about herself, and how she shut out the world after her mother’s death, but she says that she still needs him. Bea’s dad wakes up and tells her it was a good story. Bea goes outside to let Margaret know her dad is awake, but when she looks around, all the IFs have disappeared.
Back at home, Bea goes to thank Cal for his help. The landlady steps outside to open the door for Bea, revealing that nobody lives there and that the room is much smaller than she first saw it. Bea looks at one of her old drawings that she made with her parents, along with a clown-like IF that she named Calvin, revealing that Cal was Bea’s IF the entire time. Bea goes back to the room and closes her eyes to let her memories come back, and all of the IFs return before her eyes. She thanks them all for helping her out.
Bea’s dad leaves the hospital and goes to pick her up so she can move back in with him. As Margaret watches them leave, she expresses hope for the two of them, before turning to Blossom and speaking to her. Blossom then gasps with delight.
Before the credits roll, Cal goes around helping the other IFs reunite with their former kids, who are now grown ups but still able to see them. Cosmo reunites with his old kid at a convenience store where he works, while Uni reunites with the receptionist at Jeremy’s job, and Ally rejoins the nurse that tended to Bea’s dad. Benjamin also ends up getting a dragon IF to join him. When they return to their house, Bea’s dad trips over an invisible IF named Keith (Brad Pitt), who was his IF as a child.
After the credits, there is a brief montage of clips featuring Lewis, followed by a dedication to Louis Gossett, Jr.