In the fictional town of Oakton City, a purple squirrel named Surly and his mute rat partner Buddy reside in Liberty Park where their thieving reputation has made them outcasts. A group of urban animals led by Raccoon and his cardinal assistant, are running low on food for winter. Red squirrel Andie and gray squirrel Grayson compete with Surly and Buddy to scavenge from a peanut cart manned by Lucky and Fingers who are casing a bank. The squirrels’ efforts inadvertently end with the cart’s propane tank exploding in the park after it’s cord was bitten by Lucky’s pug Precious. The runaway cart ends up destroying the tree, where the animals store their food. Surly is banished and Buddy goes with him.
In the city, they find Maury’s Nut Shop. Adjacent to the bank, it is a criminal hideout used by Lucky, Fingers, their boss Percy “King” Dimpleweed and Knuckles, who plan to break through the wall and replace the bank’s cash with nuts. King’s girlfriend, Lana, believes King has gone straight and the nut store is legitimate.
Raccoon sends Andie and Grayson to the city to find food, but they get separated. Andie recovers Lucky’s dog whistle, which Knuckles threw out and Surly had used against Precious, and threatens to dispose of it if Surly does not share the nuts he is going to take. Surly accepts and unwittingly befriends Precious after threatening her with the whistle. Andie informs the park community of the plan. Raccoon reluctantly goes with the plan and assigns Mole and the Bruisers to go with her. Surly eventually learns from Mole that Raccoon’s policy is to control the food supply in order to control the animals, and that Raccoon plans sabotaging the nut bonanza. When Andie does not believe him, Surly leaves even when Grayson reunites with them.
After fending off street rats who work for Raccoon, Surly and Grayson chase the criminal gang’s getaway truck, which carries Raccoon and the other animals. Surly fights off Cardinal, and Mole defects from Raccoon and reveals the truth to the animals, resulting in Raccoon being voted out of the park community. King and Knuckles use the dynamite inside the empty truck to blow up a police barricade at a dam, but the police shoots the tire on the truck that falls from the dam. It explodes after Surly gets himself and Andie off it, and they fall into the river below. Surly makes it to a log, but finds Raccoon, King and Knuckles survived the explosion. Raccoon tries to kill Surly, but the nuts’ weight begins to break the log. The animals arrive to rescue them, but Surly, deciding to be selfless in order to protect his friends, lets go of the log and falls into the waterfall with Raccoon. The park community, now sees the good side of Surly, mourning him.
The nuts make their way to Liberty Park. King and his associates are arrested as Lana breaks up with King. Andie and Buddy are still mourning over Surly, and when Precious learns what happened, she finds Surly’s unconsciousness body near the river. She has Buddy come look at it. Doleful to see his best friend gone, Buddy says his first two words: “best friend”. Surly wakes up and hugs with Buddy. Afterward, Precious leaves to meet Lana, who plans to run Maury’s Nut Shop. Finding Surly alive, Andie embraces him and suggests to tell the other animals of his heroism. However, Surly declines, yet gains a willingness to work with others, and goes into the city with Buddy, allowing Grayson to take credit for the nuts 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 their ordeal and are sulking on a harbor buoy surrounded by sharks while coming up with another plan. In the post-credits scene, Precious chases Mole for holding a bone that she wants and he drives her away with the dog whistle.