At the beginning of the story, Stanley Yelnats IV, a shy, overweight boy who always ends up in the wrong place at the wrong time,supposedly due to a family curse, has been wrongly accused of stealing the baseball player ClydeLivingston's shoes from a charity auction to benefit a homeless shelter. The judge sentenced Stanley to 18-months at Camp Green Lake juvenile detention facility.
At Camp Green Lake, Stanley and his fellow campers, all delinquents, are forced to dig holes to "build their character". Stanley later learns the Warden of Camp Green Lake is not interested in building the boys' character, but instead is searching for a buried treasure, which she has not found. After some time, Stanley finds a lipstick tube enscribed with "KB", the initials of the Wild West outlaw, Kissin' Kate Barlow.
In a flashback, the author tells the story of the origination of the Yelnats' family curse. Over 110 years ago, Stanley's Latvian ancestor, Elya Yelnats fell in love with Myra Menke, a beautiful local girl whose father will let her marry the man with the largest pig on her 15th birthday, and Elya finds himself competing with a middle-aged pig farmer. Elya's friend and a Gypsy, Madame Zeroni, though opposed to his marrying her, agrees to help him raise the largest pig if he agrees to carry her up a mountain and sing her a lullaby. Madame Zeroni promises he will win Myra's hand by doing this or he and his family for generations to come will be cursed.
When Elya later sees that Myra is indeed as stupid as Madame Zeroni had said, he changes his mind about marrying her and gets on the first boat to America, forgetting about his promise to Madame Zeroni. Thereafter, every son in the family is called Stanley (as it is "Yelnats" spelled backward), is taught Madame Zeroni's mysterious lullaby, and is cursed with bad luck.
The second story features Katherine Barlow, a White schoolteacher in Green Lake, Texas, over 110 years ago, and her blossoming romance with Sam, a Black onion seller. Once the townsfolk of Green Lake learn of Katherine and Sam's romance, they turn against both Katherine and Sam due to ill-favored views on interracial coupling. Charles "Trout" Walker, who tried to win over Katherine's heart, leads the charge behind the angry town mob and kills both Sam and his beloved donkey, Mary Lou. Katherine, having gone insane with rage and heartbreak, becomes an outlaw named Kissin' Kate Barlow and ends up stealing all of Stanley Yelnats' fortune while leaving him stranded in the desert.
After 20 years, Kissin' Kate goes back to Green Lake, which is now a ghost town. Trout Walker and his wife Linda find Kissin' Kate Barlow and demand to know where she has buried her treasure. Kissin' Kate Barlow opts to die from the lethal bite of a Yellow-spotted lisards instead of telling Trout where she's hid her treasure. Trout and his descendants spend their lives digging for the treasure and end up building Camp Green Lake for delinquent boys, to speed up the recovery digging process.
Back in the present day, the Warden's heavy hand of having the boys dig more extensively for the treasure leads to several dramatic instances causing Zero, a silent boy who's real name is Hector Zeroni, to run away into the desert. Stanley, Zero's only friend, runs away himself the next day to find Zero, worried about his chances of surviving the harsh desert elements. Stanley finds Zero in an abandoned rowboat and sees a mountain resembling a thumb.
Stanley recalls the story of his great-grandfather's bad luck of getting robbed by Kissin' Kate and how he survived by "finding refuge off God's thumb".
Zero and Stanley struggle to climb the mountain due to their lack of water and clean food. When Stanley finally reaches the Big Thumb, Zero has passed out from being very ill. Stanley uncovers groundwater and a field of onions, which the boys eat and start to gain their strength back. While they are up there, Stanley sings to Zero the lullaby he was taught, and as it just so happens that Zero is a descendant of Madame Zeroni, this finally breaks the Yelnats family's curse.
Stanley proposes to Zero that they make their way back to Camp Green Lake so they can try to find Kissin' Kate's buried treasure. The boys are successful and find a old suitcase. Before the boys are able to leave with the suitcase,they are surrounded not only by several deadly yellow-spotted lizards, but the harsh Warden, Mr. Pendanski and Mr. Sir who wait for the boys to die from a lizard's bite. The boys are saved by their massive consumption of onions, the smell of which the lizards hate.
The protection of the resting lizards buys them enough time for a surprise visit from Stanley's attorney who arrives at Camp Green Lake with the Texas Attorney General requesting Stanley's release. When the Warden demands the suitcase back, Zero tells her that it has Stanley Yelnats' name on it. Kissin' Kate's treasure was actually Stanley Yelnats I's treasure(full of jewels, deeds, stocks and promissory notes), which rightfully belonged to Stanley and his parents.
Stanley uses the bonds to get a new house for his family, and Zero hires a team of investigators to find his missing mother. In a final scene, Clyde Livingston, along with the Yelnats and the Zeroni's celebrate the success of Stanley's father's product, named Sploosh, a foot odor perfume. Zero's mother (we assume since the author doesn't say for certain) sings a song to him, which turns out to be slightly different version of the original lullaby Madame Zeroni taught Elya Yelnats.
The Warden, being desperate for money, has to sell Camp Green Lake. The Attorney General buys it, and it is later turned into a girl scouts camp. A few weeks after Stanley and Zero leave the camp, the first drop of rain falls onto the dry barren land of Camp Green Lake.