RJ (Bruce Willis), is a raccoon who lives in Tucson, Arizona while foraging for food, encounters the hibernating black bear Vincent (Nick Nolte), and his large cache of commercially-packaged food. RJ tries to steal it, but instead wakes Vincent and causes the food to be crushed by a truck on a nearby road. Fearful of being eaten by Vincent, RJ promises to restore the cache within the week when Vincent has fully awakened from hibernation. RJ finds a nearby suburban community that has been recently erected, and a small forested plot where a pack of hibernating animals have just awoken, surprised to find a large hedge that separates the forest from the human community. Verne the box turtle (Garry Shandling), the group's elder, urges the others to start stashing food for next year. RJ appears to the group and tells them they can collect all the food they will need within a week by raiding the humans' trash and homes. Verne is extremely pessimistic about crossing the hedge, but RJ is able to convince the others to join him.
Initially, the animals only raid for food at night, but RJ realizes he needs to work faster to restore Vincent's cache, and organizes daring daytime stunts, such has having the opossum, Ozzie (William Shatner), feign being run over by a car allowing the other animals to steal food from it. Verne becomes extremely annoyed at RJ putting his "family" in danger. Meanwhile, Gladys Sharp (Allison Janney), the president of the development's homeowner association, realizes they have a vermin problem, and calls for help from Dwayne LaFontant (Thomas Haden Church), aka "The Verminator". Dwayne installs a high-powered extermination system in Sharp's backyard, including a contraband product known as the De-Pelter Turbo.
After one raid, RJ is surprised that the other animals now consider him part of their family, and provide him with a luxurious spot using items they've stolen from homes. RJ feels guilt over using the animals and attempts to tell the truth to Verne, but cannot do so. Meanwhile, Verne, still worried about his family's safety, attempts to return all the stolen food to the humans; RJ finds out and tries to stop him, but the wagon the food is on is dragged by a playful rottweiler, Nugent (Brian Stepanek), and eventually is destroyed. The other animals upon learning, are angry at Verne, who tries to convince them of RJ's manipulation, and accidentally makes a remark which convinces the animals he values himself above the rest of them.
With only one day before Vincent's deadline, RJ helps Verne reconcile with his friends and convinces the animals to do one more raid of Gladys' home after she has received a large supply of food for a dinner party the next day. They use Stella (Wanda Sykes), the skunk to lure Gladys' Persian cat Tiger (Omid Djalili) away while the other animals enter the kitchen and raid Gladys' pantry. By dawn, they are nearly done when RJ spots one last item to replace on Vincent's list, a can of "Spuddies" potato chips; despite Verne trying to get them to leave, RJ insists on getting the can, forcing him to reveal the truth about the food and Vincent. Gladys wakes up and catches the animals in the act. After, Stella goes into the kitchen and sprays her stench. As the animals try to flee, Dwayne comes in and is able to catch them all except for RJ, who abandons the group to return the food to Vincent.
As Dwayne starts to drive away with the caged animals, RJ delivers the food to Vincent, but at the last moment, has a change of heart and uses the wagon with the food to catch up to Dwayne's van, followed by an angry Vincent. The impact stuns Dwayne and frees the other animals, who turn the van around to return home. Meanwhile, RJ is chased by Vincent atop the van, refused to allow to come inside by the other animals who consider him a traitor. Eventually, Verne is able to convince the other animals that RJ is trying to help them, and they turn to help RJ defend himself from the bear. With no control, the van eventually makes a jump and flies through Gladys' home, destroying it.
The animals flee into the hedge, trapped by Vincent on one side and Gladys and Dwayne on the other. RJ and Verne come up with a plan, initiated by giving the hyperactive squirrel Hammy (Steve Carrell) an energy drink. RJ jumps out of the hedge to lure Vincent into Gladys' yard, while Hammy, moving at superhuman speed, activates the new extermination system, the De-Pelter Turbo. Gladys, Dwayne, and Vincent fall into a pile as the high-powered system comes on-line, producing a large beam of bright light that fries and stuns the trio and drops a cage upon them. Vincent is taken away by animal control to the Rockies, while both Gladys and Dwayne are charged with the highly-illegal extermination system, though Gladys retaliates by attacking an officer and tries to escape but is soon pinned down by another officer while Dwayne is able to escape from custody only to run into Nugent, who savagely chews on him. The animals regroup in the forest, and Verne assures RJ that if he had told them he needed help, they would have gladly given it because "that's what families do", and re-welcomes him to their family; Tiger, also now owner-less but attracted to Stella, is also welcomed. The animals find that while Hammy was in his caffeine-charged state, he had refilled their food cache with nuts to satisfy them for the year.
In a post-credits scene, the animals go to the vending machine seen in the beginning of the film and operate it in such a way that every product falls into the access bin. However, the amount of snacks prevents the access door from opening, prompting "Well, this is anti-climactic" from Hammy.
Meanwhile, on another side of the ocean, a family of criminally-inclined great white sharks has a problem with one of their sons, Lenny (Jack Black) (who is a Vegetarian) . Lenny refuses to act the part of a killer and wishes to not have to live up to those expectations. Finally his father, Don Lino (Robert De Niro) loses patience and orders Lenny's more savage big brother Frankie (Michael Imperioli) to show Lenny the ropes. As the two sharks set out to go in accordance with their father's wishes, Frankie spots the scene where Oscar is being electrocuted by Ernie and Bernie (Doug E. Doug & Ziggy Marley), Sykes' two Jamaican Physalia physalis thugs, and sends Lenny off to attack. The jellyfish spot Lenny and swim off, leaving Oscar alone with him. Lenny frees Oscar but fails to trick Frankie, who becomes annoyed and charges at Oscar when an anchor falls and kills him. Lenny flees, overcome with grief and guilt. As no one saw the deed done and Oscar was seen near the body, everyone thinks he did it, and Oscar sees this as the chance to both redeem himself and receive his fame.
Oscar comes back to the city with a new title of the Sharkslayer. Sykes becomes his manager, Lola becomes his girlfriend, and Oscar moves to the "top of the reef" to live in luxury. At the same time, Don Lino has everyone out looking for Lenny, and when several get close to Oscar's town the other fish expect him to drive them away. On the way he meets Lenny once more who forces Oscar to let him stay with him because he does not want to go home. Soon Angie finds out about the lie and threatens to tell everyone but Oscar and Lenny convince her to keep quiet. Although Oscar desires to please everyone, he soon discovers that he pleases no one; his paramour Angie is heartbroken by the fact that Oscar is no longer honest, while her hedonistic rival Lola repeatedly reminds Oscar that he has her only as long as he is famous. With Don Lino planning revenge, Oscar and Lenny stage an event where Lenny pretends to terrorize the town and Oscar must defeat him, throwing him into the depths of the ocean. Though this further cements Oscar as the Sharkslayer, it greatly angers Don Lino. Oscar leaves Lola for Angie after Angie reveals that she had feelings for Oscar even before he became famous, but this leaves Lola determined to get revenge.
Oscar buys some Valentine's Day gifts for Angie, but before he can present them to her, he finds that Don Lino has kidnapped Angie in order to force a sit-down. Lenny comes along, now disguised as a dolphin named Sebastian. They arrive at the meeting to find Lola next to Don Lino, while Angie is bound and gagged with duct tape and presented to Don Lino on a plate, who prepares to eat her if Oscar doesn't comply. Oscar just laughs and Lenny as "Sebastian" lunges forward to scoop Angie into his mouth, freeing her from Don Lino and giving Oscar dominance over the sharks. However, he spends too much time threatening the sharks and doesn't realize how much pain Lenny is in, and Angie is regurgitated onto the table. Don Lino suddenly realizes it's Lenny and proceeds to chase Oscar through the reef, but Oscar heads for the whale wash and ends up trapping both sharks. Given an ovation by the other fish, Oscar confesses that he is not a "Sharkslayer" and that it was an anchor that had killed Frankie. He then strongly urges Don Lino not to prejudge people before he knows them properly and to not make the mistake he made in prejudging his wealth, so Don Lino and Lenny reconcile. Oscar forsakes all the wealth he has acquired, makes peace with the sharks, becomes manager of the Whale Wash (now frequented by sharks), and starts dating Angie and starts to have a happy, honest life.
In the post-scene credits Lola comes to see Oscar in the top of the reef but all she finds is Crazy Joe a hermit crab.