n the fictional town of Oakton, a selfish purple squirrel named Surly (Will Arnett) and his rat partner Buddy who does not talk reside in Liberty Park and their thieving reputation has made them outcasts. A group of urban animals led by Raccoon (Liam Neeson) and his Cardinal assistant (who mostly chirps) store food for winter in a giant tree in the park called Liberty Park. Raccoon is informed by his servant Mole (Jeff Dunham) that there is a food shortage in the park. Surley and Buddy's attempt to rob a peanut cart goes haywire when it is impeded by Raccoon's helpers, a compassionate red squirrel named Andie (Katherine Heigl) and the 'park hero', a gray squirrel named Grayson (Brendan Fraser) whose heroic antics prove to be incompetent. A selfish Surly ignores Andie's help and tries to get a bag of nuts while the owner Lucky and his associate Fingers gets distracted by a bratty girl scout customer and a police officer that the girl issues her complaint to. The heist also gets invaded by Lucky's pet pug named Precious (Maya Rudolph). After fending her off by having her bite the pipe of a propane tank, Surly and Buddy escape with the cart and Andie manages to guide it to Liberty Park. Surly threatens Andie and Grayson with a torch, unwilling to share the food, but accidentally causes it to ricochet across the park. Although the animals (except for Grayson) get off safely, the cart is sent into the tree, where it explodes along with the tree and the animals' food supply. Grayson however, survives the ordeal. When Surly is identified as the culprit, Raccoon banishes him from Liberty Park following a unanimous vote forcing him to survive in the city.
Buddy attempts to be with Surly who tells him to leave after he unknowingly contributed to his exile. After escaping from wild street rats, they find a nut store called Maury's Nut Shop and attempt to rob it to feed themselves. After entering the store, they discover that it's a criminal hideout used by Lucky, Fingers, their mob boss Percy "King" Dimplewade (Stephen Lang) who has recently gotten out of jail, his silent partner Knuckles, and his girlfriend Lana (Sarah Gadon). Raccoon sends Andie and Grayson to find food only for them to get separated upon Grayson fighting a street rat. Precious also serves as the guard dog there. King plans to rob the Oaken Bank and replace the cash with nuts. Surly and Buddy see that the only way to get to the nuts and to avoid Precious is with a dog whistle that Lucky has. The two of them are thrown out by Knuckles since he can hear it. While trying to find the whistle, Surly crosses paths with Andie who gets the whistle and threatens to dispose of it if Surly does not share the food he's going to take. Reluctantly, Surly accepts and unwittingly befriends Precious after threatening her with the whistle. Andie informs the park community of the plan. Although they have a lack of faith in Surly, Raccoon and the rest of the park community agree to go along with it. Andie gets help from Mole and the trio of Groundhog Bruisers lead by Jimmy (Gabriel Iglesias).
When the first attempt to rob the store fails, Surly eventually learns from Andie that Raccoon planned on double crossing him and Surly leaves after an argument. Back at Liberty Park, Raccoon's true colors are revealed, a power hungry con artist who keeps food from the animals to have his leadership kept and only Mole and Cardinal know about it. Surly ends up chasing after King's truck as the animals help him while Grayson fights off Cardinal who is sent flying into the window of a building where a Cat Show is being held. While in the truck upon Raccoon's arrival, Mole defects from Raccoon and reveals this info to the animals with Surly resulting in Raccoon being voted out of the park community at Grayson's suggestion. King and Knuckles uses the dynamite inside the empty truck to blow the police out, but it hangs and falls over the bridge where it explodes, after Surly gets himself and Andie off it before they fall into the river. Surly makes it to a log, but finds Raccoon, King and Knuckles surviving the explosion. Raccoon tries to kill Surly, but the nuts weight begins to break the log. The animals arrive to rescue them, but Surly, decides to be selfless in order to protect his friends, lets go of the log and falls down into the waterfall with Raccoon apparently. The park community, now seeing the good side of Surly, mourn him in honor of the most selfless act he committed in years.
The food makes its way into the Liberty Park, where the animals gather around in joy as their food troubles are over. King and his associates are arrested as Lana appears to end her relationship with King. Andie and Buddy are still mourning over Surly and when Precious finds out what happened to her friend, she eventually finds Surly's apparent dead body near the river. She has Buddy come and look at it. Doleful to see his best friend gone, Buddy says his first two words "best friend". Surly reveals that he was actually unconscious and hugs Buddy and Precious licks Surly's face (which she wanted to do since she got involved in Surly's heist) and leaves to meet up with Lana who plans to run Maury's Nut Shop in Lucky's place. Finding that Surly is alright, Andie embraces him and tries to get him to come to the other animals so he can tell of his heroism. But Surly, feeling as though it was the other animals that were the true heroes, refuses yet gains a willingness to work with others. He goes along to the city with Buddy allowing Grayson to take credit for the food making it to the park.
During the credits, the animals and humans dance with an animated PSY as he performs "Gangnam Style." In a mid-credits scene, Raccoon and Cardinal are shown to have survived the ordeal and are sulking on a harbor buoy surrounded by sharks while trying to come up with another plan. In the post-credits, Precious chases Mole who is holding a bone that Precious wants. Mole drives Precious away with the dog whistle.