A Jack Russell Terrier named Max lives with his owner Katie in a Manhattan apartment. While she is at work during the day, he hangs out with other pets in the building: tabby cat Chloe, pug Mel, dachshund Buddy, and budgerigar Sweet Pea. One day, Katie adopts Duke, a large mongrel from the pound, leaving Max jealous because of her divided focus on Duke. Enraged by Max’s attitude towards him, Duke tries to abandon Max in an alley, but they are both attacked by cats led by Sphynx cat Ozone who removed both dogs’ collars and leave them to be caught by Animal Control. Duke fears that he will be put down if he goes back to the pound. To her desperation, Gidget, a white Pomeranian actually discovers that Max is missing.
Meanwhile, he and Duke are rescued by a white rabbit named Snowball, the leader of “The Flushed Pets” – a gang of sewer-dwelling animals who hate humans because their owners mistreated them. After Max and Duke pretend to despise humans as much as they do by saying they killed their owners, the Flushed Pets invite them to join. Before they can prove their loyalty by allowing a one-fanged viper to bite them, Snowball learns from the cats that Max and Duke are domesticated. The two dogs escape the sewers and board a ferry to Brooklyn, inadvertently killing the viper in the process; Snowball vows to kill them and leads the Flushed Pets after them.
Meanwhile, Gidget recruits a red-tailed hawk named Tiberius to find him, but mistakenly returns carrying Ozone, whom Gidget coerces into telling what he knows about the dogs. They then enlisted Mel, Buddy, Chloe, guinea pig Norman and Sweet Pea. On the way, they meet Pops, an old Basset Hound, who helps Gidget and the pets find Max. Meanwhile, Max and Duke raid a sausage factory for food. Gidget and co. encounter Snowball, who vows to kill them as well, and Norman is captured as the rest of Gidget’s team flees.
Meanwhile, Duke tells Max about his previous owner, Fred, an elderly man who adopted him as a puppy and loved spending time with him. One day, Duke got lost while chasing a butterfly and was caught by Animal Control, but Fred never came to claim him. Max convinces him to visit Fred’s house in a nearby neighborhood, confident Fred will still love him and take him back. When they arrive at Fred’s house, they learn from the resident cat Reginald that Fred has died. Heartbroken, Duke accuses Max of attempting to get rid of him and barks at the new homeowners who had just returned to the house, who call Animal Control. The handlers catch Max, but Duke interferes long enough for Max to escape and ends up being captured instead.
While trying to rescue Duke as he follows the Animal Control van, Max is attacked by Snowball who tries to kill him. However, when his gang is captured, Snowball realizes that he and Max must work together to rescue them. They drive a city bus into the van on the Brooklyn Bridge, stopping traffic. The Flushed Pets encircle Max, unaware of his partnership with Snowball, but Gidget and her team save him. When Gidget is using her kung-fu fighting skills, Max starts to fall in love with her. The van gets stuck in scaffolds and the Flushed Pets escape. Once Max got the keys to Duke’s cage, the van plummets into the East River with him inside. Max is unable to free Duke, so Snowball jumps into the river to retrieve the keys, allowing them to escape the sinking van. Once out of the river, Snowball realizes how good being heroic feels.
The entire group returns to the apartment block by pig-driven taxi. Max expresses his love for Gidget, who returns his affection. Snowball and the Flushed Pets then come up with a new plan to annihilate all humans, but a little girl named Molly arrives to adopt Snowball and the remaining Flushed Pets return to the sewers. At first, Snowball resists, but gives in and lets himself become a domesticated pet. The domesticated pets return to their homes and embrace their owners, and Max and Duke finally reunite with Katie, sparking a true friendship.
In a mid-credits scene, Buddy and Mel show up in costume at a party in poodle Leonard’s apartment. Leonard’s owner returns and Tattoo crashes to the floor on the chandelier.