Orphans Jane and Alan are the wards of their wicked Uncle Barnaby, who wants to steal their inheritance. He arranges with two sailors, Gonzorgo and Roderigo, for them to be shipwrecked and lost at sea, but they are rescued by gypsies and returned to Storybook Town. Contrary Mary, the eldest daughter of the Widow Piper, believing her beloved Alan is dead, has run away with her brother, Tom-Tom, rather than agree to marry Barnaby. After a second attempt on their lives, Jane and Alan are abandoned in the Spider Forest, where they are protected by the Moth Queen. Jane and Alan arrive in Toyland, where they find Mary and Tom and seek protection from the Master Toymaker, who plots with Barnaby to create toys that kill and maim. The demonically possessed dolls turn on the Toymaker, killing him, and Barnaby uses the information to have Alan sentenced to death. Mary agrees to marry Barnaby in exchange for Alan's pardon, but after he marries her, Barnaby denounces Alan again. Tom reveals that an old law of Toyland permitting marriage between a widow and a condemned man on condition that he supports her may save Alan from the gallows. Barnaby dies after drinking a wine glass filled with poison meant for Alan. Alan is now free to marry Contrary Mary.