The story takes place before Puss (Antonio Banderas) met Shrek and Donkey, when he was a swashbuckling hero who protected the innocent.
The film starts with Puss escaping a bounty hunter and entering a nearby town. Puss learns that two murderous outlaws, Jack (Billy Bob Thornton) and Jill (Amy Sedaris) have the magic beans he's been looking for half his life, which lead to a giant's castle holding valuable golden goose eggs. When Puss tries to take them from the two outlaws, another cat with a mask interrupts. Both fail and escape, and Puss follows the cat back to his hideout, where they have both a dance and a sword fight. After getting hit in the head with a guitar by Puss during their fight, the other cat reveals that she is female, much to Puss's surprise. Puss then meets his old childhood friend Humpty Dumpty (Zach Galifianakis), who introduces her as Kitty Softpaws (Salma Hayek), one of the best cat thieves in the world. They ask him to join them in finding the beans, planting them, and getting the golden eggs which lie at the top. Puss refuses to work with Humpty due to a past betrayal that left him falsely accused for robbery, alienating him from his hometown and adoptive mother. Puss abandoned Humpty in disgust, leaving him to be apprehended by the authorities.
After Humpty explains to Puss that he wants a second chance, Puss agrees to help him obtain the beans, making it clear that he is doing it for the town and his mother, not for Humpty. They manage to successfully steal the beans from Jack and Jill and manage to elude them after a fast paced canyon chase. As Humpty leads them to the spot where they must plant the beans, Puss and Kitty's relationship begins to grow from rivalry into friendship. When they finally reach the spot and plant the beans, the trio ride the growing beanstalk up into the clouds where the giant's castle is. Humpty tells them that the giant living in the castle is dead, but they must be wary of the Terror, a fearsome monster that guards the Golden Goose. When they realize that the golden eggs are too heavy to carry back, they instead decide to steal the Goose itself and manage to escape the castle and the Terror. While celebrating their victory, the group is ambushed by Jack and Jill, with Puss getting knocked out.
When Puss wakes up, he immediately tracks Jack and Jill back to his old hometown, where he finds out that the entire heist was a plot by Humpty to lure him back to his hometown to be arrested, as revenge for abandoning him to the authorities. Jack, Jill, and even Kitty were involved. After pleas from his mother, Puss gives himself up to the guards while Humpty donates many golden eggs to the town and becomes a hero. While in prison, Puss meets the original Jack from the Jack and the Beanstalk story, who warns him that the Terror is in fact the Golden Goose's mother, and it will stop at nothing to get its child back. A repentant Kitty helps Puss break out of prison. He then convinces Humpty to help him fight off the Terror, saying that he knows Humpty is a good person at heart, and he will be forgiven if he helps save the town. The Terror finally arrives at the town, revealing itself to be a giant goose. Using the Golden Goose as bait, Puss and Humpty manage to lure the Terror out of the town, but Humpty and the Goose are knocked off a bridge with Puss holding on to them. However, Humtpy knows Puss cannot hold both of them up and he lets go, sacrificing himself to save the Goose and the town. Humpty's shell cracks open to reveal that he was a golden egg on the inside. The Terror then takes the Goose and Humpty's body away back to the giant's castle.
Puss is forced to flee the town because he is still an outlaw, but his efforts to save the town make him a hero among the local townspeople. Puss and Kitty get away from the guards once more, and Kitty says she will see him again soon, showing that she has taken his boots. In the epilogue, Jack and Jill are recovering from their injuries after being crushed by the Terror, Humpty is shown once again in his regular egg form as he rides the Terror in the clouds, and Puss and Kitty head back to dance at Kitty's hideout, where they finally kiss while dancing.