Stanley Yelnats IV is an overweight teenage boy from a poor family, whose future fortune depends on his inventor father discovering the secret to curing bad foot odor. The Yelnats family is said to be cursed: Stanley's great-great-grandfather did not honor a promise he made to an old woman with magical powers, and misfortune has followed him and his descendants ever since. Stanley is unlucky enough to be wrongly accused of stealing baseball star Clyde "Sweet Feet" Livingston's shoes, and instead of being locked up in prison, he is sent to Camp Green Lake, a juvenile detention and correction facility in the middle of the desert.
After a long and lonely bus ride, Stanley arrives at the camp and meets the lazy and nasty Mr. Sir, one of the camp supervisors. He is warned to watch out for Warden Walker. Stanley also meets Mr. Pendanski, another camp supervisor. He is assigned to Tent D, where he befriends his tent mates and slowly learns the ropes of surviving in the harsh conditions of the camp: terrible food, limited shower time, an uncomfortable bed. Stanley becomes particularly good friends with a small but tough boy named Zero, whom we later discover is Hector Zeroni, a descendant of the woman who cursed the Yelnats family.
Stanley and the other boys are forced to dig a hole every day, five feet deep and five feet wide. The work is exhausting, especially in the shadeless heat of the day, and potentially dangerous: the lake is populated by yellow-spotted lizards, whose venom is strong enough to kill a person. The boys are told that the digging will teach them to work hard, and eventually facilitate their rehabilitation into society, but in reality, the Warden has a hidden agenda. She wants to find the treasure stolen and hidden by infamous bandit Kate Barlow.
The sad story of Kate Barlow is revealed later in the novel, although we learn early on that she is the one responsible for robbing Stanley Yelnats' great-grandfather of his stock market fortune and plunging the family into financial difficulties. Shortly before that time, when Green Lake was still full of water, Katherine Barlow was a beautiful young schoolteacher who fell in love with a black man - an impossible match, given the racism of the era. Her lover Sam was killed after they were caught kissing, and Kate became mad with grief, going on a killing spree that started with the sheriff and expanded into a career of banditry and murder. She earned the nickname "Kissing Kate" for kissing each of her victims with a full mouth of lipstick, leaving the mark of her lips on their skin. Legend has it that she left a great treasure buried somewhere in the desert before she committed suicide.
In Camp Green Lake, Stanley begins to teach Zero how to read. Zero eventually runs away from the camp, and a couple of days later Stanley steals the water truck and drives a short way before crashing the truck and following Zero on foot. Stanley finds Zero under an overturned and abandoned boat, eating the decades-old leftovers of the peaches that Katherine Barlow loved to make.
Since Zero is the descendant of Madame Zeroni, Stanley - although he does not know it - has the chance to put things right and break the curse that has plagued his family for generations. Stanley's great-great-grandfather received a piglet from Madame Zeroni, and instructions on how to turn it into a prize-winning pig, in return for promising to take Madame Zeroni up a mountain and to sing her a song while she drank from a life-giving stream. It was by forgetting this promise that he brought the curse down on him and his descendants.
In the present day, Stanley and Zero find themselves at the thumb-shaped mountain that Stanley spotted from afar and they begin to climb it, hoping to find water. Zero becomes too weak to continue, so Stanley carries him up - thereby fulfilling his great-great-grandfather's promise, albeit several generations late, and breaking the curse. The two boys spend a week at the lush green top of the mountain.
After coming down, the two friends go back to Camp Green Lake and find the treasure. They are caught by the warden and her supervisors and are almost killed. Stanley's lawyer shows up and takes him, Zero, and the treasure back to Stanley's family. Camp Green Lake is shut down, and the Warden sells the land to an organization that plans to turn it into a Girl Scout camp. Stanley and Zero split the treasure, and Zero uses his half to find his mother. Stanley's father is finally able to find, patent, and sell a cure for foot odor. The Yelnatses and Zeronis live the rest of their lives in comfort.