Stanley Yelnats, a boy who has bad luck due to a curse placed on his great- great-grandfather, is sent to Camp Green Lake, a juvenile detention camp, for a crime he did not commit. Stanley and the other boys at the camp are forced to dig large holes in the dirt every day. Stanley eventually realizes that they are digging these holes because the Warden is searching for something. As Stanley continues to dig holes and meet the other boys at the camp, the narrator intertwines three separate stories to reveal why Stanley's family has a curse and what the Warden is looking for.
When he was a boy, Stanley's great-great-grandfather, Elya Yelnats, received a pig from Madame Zeroni, a gypsy, in exchange for a promise. Elya's promise was that after the pig grew strong he would carry Madame Zeroni, who only had one leg, up a mountain and sing her a song that she had taught him. After becoming disillusioned with the girl he thought he loved, however, Elya hops a boat to America, forgetting his promise to Madame Zeroni. Elya marries and has a child in America and always thinks about Madame Zeroni, who he believes has cursed him because of his failure to fulfill his promise. He knows that Madame Zeroni's son lives in America, but Elya never finds him.
One hundred and ten years before Stanley arrives at Camp Green Lake, the town of Green Lake is a beautiful place where peach trees bloom throughout the spring. In this Texas town, the schoolteacher, Katherine Barlow, falls in love with Sam, the onion seller. Sam sells onions to eat and to use for medicinal purposes. While Katherine and Sam are alive, racism is institutionalized in the United States and it is against the law for a black man to kiss a white woman. Because Sam is black and Katherine is white, the people in the town become irate when they find that Katherine and Sam have kissed. Charles, or Trout, Walker, the richest man in town has always wanted to marry Katherine. He is already mad that Katherine does not wish to go out with him so when he finds out that she is in love with Sam he gathers the townspeople to burn the schoolhouse and attack Sam. Katherine seeks help from the local sheriff but instead finds that the sheriff, who makes lewd advances towards her, also wants to kill Sam. Katherine and Sam attempt to escape but their boat is destroyed while only half way across the lake and Sam is killed. Katherine is driven mad by her grief and becomes an outlaw known as Kissin' Kate Barlow. Her name refers to the fact that she kisses the men she kills, leaving a lipstick imprint of her lips on their faces. In her twenty years of robbing people in the west, she happens to rob Stanley's great- grandfather while he is on his way from New York to California. She buries Stanley's great-grandfather's money somewhere and even though Charles Walker and his wife Linda try to torture her into revealing its location, Kate dies before anyone can find out where the money is hidden. After the day that Sam is killed, rain stops falling on Green Lake and the lake dries up.
Because Green Lake dries up, the citizens of the town all move away and by the time that the land is serving as Camp Green Lake, the only people there are juvenile delinquents. Stanley has a hard time digging holes there due to the incredible heat and the hard, dry land. At one point Stanley digs up half of a lipstick tube that has the initials KB on it. Stanley knows that the Warden, who happens to be a descendent of Charles and Linda Walker, is interested in this find and he speculates that perhaps Kate Barlow used to live in the area. The other boys at the camp are tough and all have nicknames. Stanley tries to stay in the good graces of X-Ray, the obvious leader of the group but this becomes harder as Stanley becomes better friends with a boy named Zero. Although Stanley and Zero, also known as Hector Zeroni, do not know it, Hector is the great- great-great-grandson of Madame Zeroni. Zero eventually runs away from camp and Stanley, in an effort to save him, follows after a few days. The two help each other to reach the top of a big mountain, which turns out to be Sam's old onion field. Because Zero is very weak, Stanley carries him up this mountain. They survive on onions for more than a week and then return to camp, planning to search for Kate Barlow's treasure in the hole where Stanley found the lipstick tube.
Stanley and Zero find a suitcase that has the name Stanley Yelnats on it. Although the Warden attempts to take the suitcase from them, Stanley's lawyer, Ms. Morengo, arrives to say that Stanley has been proven innocent and Stanley and Hector are able to leave the camp with the suitcase. It turns out that the suitcase contains many valuable items and is in fact the same suitcase that Kate Barlow took from Stanley's great-grandfather, also named Stanley Yelnats, so many years ago.
At the end of the book, it seems that the Yelnats family curse is lifted. Hector is reunited with his mother, from whom he was separated many years ago and Stanley's father finally succeeds in inventing something: a cure for foot odor. While at Camp Green Lake, Stanley has improved his physical strength and his self-confidence in addition to making a true friend. While fate has so often seemed against Stanley, in the end it serves to help him, his family, and Hector.