Pac-Man along with Ms. Pac-Man, Pac-Baby, SpongeBob SquarePants, Patrick Star, Buster & Babs Bunny, and Roger Rabbit go to visit some old friends of Roger's at a Barnyard. Otis (Kevin James) is a carefree male dairy cow who prefers to goof off rather than accept responsibility. His father Ben (Sam Elliott) is the leader of the barnyard when the farmer is away, giving the animals the safest moment to spring up being bipedal. After Otis, Pac-Man and the gang interrupt a barnyard meeting with his wild antics, Ben has a talk with his son, in which he tells him that he'll never be happy if he just goofs off, and that he should grow up one day. Otis ignores his advices and leaves to have fun with his friends Pip the mouse (Jeff Garcia), Pig the pig (Tino Insana), Freddy the ferret (Cam Clarke), and Peck the rooster (Rob Paulsen). That same day, Otis meets a new yet pregnant cow named Daisy (Courteney Cox), accompanied by another girl cow named Bessy (Wanda Sykes).
That night, Pac-Man, Ms. Pac-Man and the animals throw a massive party in the barn; all the animals are there except Ben, who watches over the fence, which marks their space. Otis is assigned his shift along with him, but he talks himself out of it, saying that he's needed for a certain role in the party barn. Ben talks with Otis and says that the day he found him alone in the meadow, the stars danced. Otis is given the privilege to party out, and the thankful son runs to the barn. Later on, Ben takes on a pack of coyotes led by Dag (David Koechner) and Wile E. Coyote, who are plundering the chicken coop. He manages to fight off the pack until he is bitten on the leg by the red coyote, making him fall. The coyotes pile on Ben, but he manages to grab Dag and escapes the pile. He threatens to punch Dag, but lets him go, scaring him and the coyotes off. The hens cheer, but Ben falls on the ground, exhausted. A hen named Etta (Andie MacDowell) runs into the barn and tells Otis and he runs outside to his father. Ben opens his mouth as if to say something, but then dies. He is then buried on his hill by the farmer. His grave was labeled, "BEN- a good cow."
After Ben's death, The Pacs and all the animals elect Otis as the new leader of the barnyard, presumably because he is a born party animal. An old mule named Miles (Danny Glover), who was lifelong friends with Ben, kicks the farmer (Fred Tatasciore) because he saw the animals on two legs, knocking him out. He along with the Pacs and their friends, shirks his duties by leaving Freddy and Peck in charge of the coop, helping three trouble-making cows called the Jersey Cows Eddy (S. Scott Bullock), Igg (Maurice LaMarche), and Bud (John DiMaggio) in teaching a lesson to a chubby brat called Snotty Boy (Steve Oedekerk), who enjoys cow tipping, and being chased by police and a helicopter on the television series COPS in the neighbor Mrs. Beady's 1960 Chevrolet Impala. Later that night, when Otis is sitting with Daisy and holds Daisy's hoof while looking up at the stars, he overhears that the coyotes are chasing a rabbit and leaves Daisy and chases after the coyotes to avenge his father. Otis tries to attack Dag and his pack, but he's outsmarted by them. Since Otis is weaker, Dag orders a deal that he and his pack will take animals here and there, and if Otis tries to stand up for all of them, they'll slaughter everyone. Otis decides to leave the barnyard, realizing that he has no chance.
The next morning, before leaving, Otis is informed that the coyotes took some hens, SpongeBob, Patrick, Roger and a chick named Maddy (Madeline Lovejoy), who is one of Otis' best friends. Otis realizes that he has been backstabbed by Dag as he wasn't expecting him and the coyotes until tonight, and sets off to rescue the poultry along with the Pacs, Buster and Babs. Otis confronts the pack, but is easily defeated after Dag bites him in the leg; however, Pip, Pig, Freddy, Peck, and Miles arrive to help Otis, along with the Jersey Cows and the gophers. Dag tries to attack Otis from behind, but Otis is alerted when Peck successfully manages to crow a warning. Otis catches Dag and he too threatens to punch him but like his father, he can't bring himself to do it. Instead he tells the coyote "Never come back". The red coyote is then swung out of the junkyard by Otis' golf skills, and a golf club. Buster and Babs then use TNT to blow up Wile E. Coyote.
That night, Pac-Man, Otis and the gang make it back to the barnyard, finding that Daisy went into labor after Otis left to face the coyotes. She gives birth to a calf whom she names Ben. Duke (Dom Irrera), the farmer's sheepdog, asks Otis if he wants to stay and be their leader. Otis agrees, and everyone cheers as he walks outside finding the stars dancing.
SpongeBob SquarePants, Patrick Star, Buster and Babs Bunny, Roger Rabbit, and Wile E. Coyote guest star in the film.