Stanley Yelnats IV is a 14-year-old boy from a hard-working but poor family that is allegedly affected by a curse of bad luck, which they blame on Stanley's "no-good-dirty-rotten pig-stealing-great-great-grandfather". Stanley's latest stroke of misfortune occurs when he is wrongly convicted of the theft of a pair of athletic shoes once owned by famous baseball player Clyde "Sweet Feet" Livingston, which had been donated to a homeless shelter to raise money.
Stanley is sent to Camp Green Lake, a juvenile corrections facility which is ironically located in the middle of a sterile desert. As punishment, the camp inmates are assigned to dig one hole each day five feet wide and five feet deep in order to 'build character'. Stanley soon begins to suspect that they are really digging to find something hidden beneath the ground.
Stanley's great-great-grandfather, Elya Yelnats, is in love with a fifteen-year-old girl named Myra Menke. However, a much older pig farmer named Igor Barkov also wants to marry her, offering Myra's father his heaviest pig in exchange for Myra's hand in marriage.
Desperate to impress Myra and her father, Elya goes to his friend Madame Zeroni for help. Despite not approving of Myra as a partner, she gives him a tiny piglet, telling him to carry it up a mountain every day, and let it drink from a stream while singing to it. Every day the water will make it grow bigger, and Elya will grow stronger. On the last day, after he carries the pig one last time, he must carry Madame Zeroni herself up the mountain to do the same, as he will then be strong enough to carry her. However, Zeroni warns him that if he does not carry her up the mountain, his family will be cursed.
Elya follows her directions, and the piglet grows to a large size, but he does not carry it up on the final day in order to have time to clean up. After the pigs weigh the same, Myra uses an arbitrary number selection tactic to choose, and Elya leaves in disgust. Forgetting his promise to Madame Zeroni, he moves to America to start a new life, falls in love, and marries, but he is beset by Zeroni's curse. The song that he sang to the piglet becomes a lullaby that is passed down among Elya's descendants, who are all named Stanley due to its palindromic relation to the name Yelnats.
Kissin' Kate Barlow
In the year 1888, the town of Green Lake is a flourishing lakeside community. Katherine Barlow, the white local schoolteacher, falls in love with Sam, an African-American onion seller, while rejecting advances from wealthy resident Charles Walker (nicknamed "Trout" due to the smell of his feet). There is an uproar in the town after Kate and Sam are seen kissing in an alley. After a mob burns down the schoolhouse, Katherine recognizes that Sam is in grave danger. She finds Sam and they attempt an escape across the lake in Sam's rowboat, but Walker and the mob intercept them with Walker's motorboat, ramming the smaller vessel and sinking it. Sam is ruthlessly shot and killed in the water, while Kate is "rescued" against her wishes. Following these actions, no rain falls upon Green Lake ever again.
The next day, Kate murders the sheriff and leaves a lipstick print on his cheek before departing to become a prominent outlaw, earning her the nickname "Kissin' Kate Barlow." Kate robs Stanley's great-grandfather, Stanley Yelnats I, of his entire fortune, but instead of killing him, she abandons him in the desert that was previously Green Lake. Miraculously, he survives after he is found by lizard and snake hunters, who believe him to be crazy. Stanley I is subsequently taken to the hospital. During his stay, he falls in love with the nurse that is caring for him, and the two later marry.
Twenty years later, Kate returns to an old cabin on the former lakeside and is tracked down by Trout and his wife Linda, who are bankrupt and desperate for money due to the two-decade long drought. They try to force her to reveal where she buried her loot, but she is bitten by a yellow-spotted lizard and dies. As she dies, she taunts them by saying, "Start digging". The Walkers are left to dig the entire area in order to find the buried treasure.
Camp Green Lake
The inmates at Camp Green Lake are forced to dig cylindrical holes five feet deep and five feet wide, which the Warden says "builds their character." They are promised the rest of their day off if they find anything that the Warden considers "interesting". Stanley finds a fossil, but Mr. Pendanski (one of the wardens) tells him that the Warden "isn't interested in fossils", leading Stanley to suspect they are looking for something in particular. During one dig, Stanley finds one of Barlow's lipstick tubes (though he does not recognize it for what it is). X-Ray, the ringleader of Tent D, asks Stanley to give him the lipstick tube so he could have the day off as he has been there the longest and deserves it. After initially refusing, Stanley obliges, and the Warden is excited by the discovery.
Meanwhile, Stanley and Zero, the smallest inmate in Tent D, who got his nickname because "he has nothing in his head", become friends. Stanley agrees to teach Zero how to read, and in return, Zero digs Stanley's hole part of the time. The camp staff discover this, and confront the boys. The argument culminates in Zero angrily hitting Mr. Pendanski with a shovel and running away, and the camp staff decide to erase their records of him and let him die in the desert. A few days later, Stanley follows Zero and finds him living under the remains of Sam's boat, eating very old jars of Kate's spiced peaches, which he calls "Sploosh". Stanley notices a mountain resembling a human fist giving the thumbs up sign, and recalls that Stanley Yelnats I claimed to find "refuge on God’s thumb". On the mountain, Zero admits that he was the one who stole "Sweet Feet" Livingston's shoes.
Atop the mountain, Stanley discovers a field of onions that was once Sam's. The boys eat the onions and find water by digging in the ground, and Stanley sings Madame Zeroni's song to Zero, Zeroni's descendant, unknowingly breaking the curse. They return to camp and unearth the treasure. Stanley's attorney appears at the camp, explaining that Stanley is innocent due to the emergence of an alibi. The Warden tries to claim they stole the suitcase from her, but Zero reveals that the name 'Stanley Yelnats' is written on it, as the suitcase had belonged to Stanley's great-grandfather. Fearing that the warden will kill Zero if he leaves him behind, Stanley refuses to leave the camp unless Zero can come along. The attorney orders the Warden to get Zero's file, but the camp staff are naturally unable to find it, and Zero is also released.
Stanley's family open the case, discovering the jewels, deeds, stocks and promissory notes stolen from Stanley Yelnats I. Using the money raised from the bonds, Stanley's family buys a new house and Zero hires a team of investigators to find his missing mother; meanwhile, the drought at Green Lake is brought to an end by rainfall. The family's luck seems to change as if in response to Stanley's fulfillment of his ancestor's promise (a suggestion left purposely ambiguous by the narration). In a final scene, Clyde Livingston and his wife, along with the Yelnats and Zeroni families, celebrate the success of Stanley's father's antidote to foot odor, composed of preserved and fermented spiced peaches and onions and named "Sploosh" by Zero. The Warden is forced to sell Green Lake to "a national organization dedicated to the well-being of young girls", which turns it into a Girl Scout camp.