There's no real camp or lake at Camp Green Lake. Though it was once the largest lake in Texas, it's been dry for the last 110 years. It's now a camp for "bad boys," where the boys dig holes every day. Stanley Yelnats is the only passenger on the bus to Camp Green Lake. He tries to pretend that he's going to an actual summer camp and hopes he'll make friends, as he's the victim of terrible bullying at home due to being overweight. Stanley is innocent of his crime; he was convicted because of his no-good-dirty-rotten-pig-stealing-great-great-grandfather, who supposedly stole a pig and thereby cursed all of his descendants. No one in Stanley's family truly believes this, though things do go wrong a lot. Stanley steps off the bus and a man named Mr. Sir handles Stanley's intake. Stanley changes into an orange jumpsuit as Mr. Sir tells him he'll be required to dig a hole five feet deep and five feet across every day and that he should report anything interesting he finds to one of the counselors.
Stanley meets his counselor, Mr. Pendanski, and his fellow campers in Tent D. Though Mr. Pendanski uses their given names to introduce them, the boys introduce themselves as X-Ray, Squid, Magnet, Armpit, Zigzag, and Zero. Stanley takes his four-minute cold shower, eats dinner, and the other boys don't believe that Stanley is at camp for stealing the famous baseball player Clyde Livingston's shoes. The shoes fell from the sky onto Stanley as he was walking home from school and he ran with the smelly shoes to his father, feeling as though the shoes were the key to Stanley's father's latest invention. His parents had been too poor to hire a lawyer to defend Stanley.
As Stanley begins to dig his first hole, the narrator tells the story of Elya Yelnats, Stanley's great-great grandfather. At age fifteen in Latvia, Elya fell in love with Myra Menke. Myra's father, however, wanted Myra to marry Igor Barkov, a 57-year-old pig farmer. Elya went to his friend Madame Zeroni for help. She insisted that Myra was silly and spoiled, but she agreed to help Elya anyway. She gave Elya a runty piglet and instructed him to carry the piglet up the nearby mountain daily, where the pig was to drink from a stream while Elya sang a special song to it. After Myra's birthday, Elya was to then carry Madame Zeroni up the hill. If he didn't follow through, Madame Zeroni would curse his descendants for eternity. Elya did as he was told and both he and the pig grew big and strong. On the last day, however, Elya took a bath instead of carrying his pig up the hill. The pig weighed just as much as Igor's, so Myra's father allowed Myra to choose her husband. Myra refused to choose, so Elya got on a ship bound for America and didn't realize until later that he'd broken his promise to Madame Zeroni. The curse started to seem real in America, after Elya married and had the first Stanley.
In the present, Stanley finishes his first hole. He spends a few minutes in the rec room, which is called the Wreck Room, and realizes his tent mates have christened him the Caveman. He then writes a letter to Stanley's mother lying to her about the fun he's having at camp. He notices Zero reading over his shoulder. On the second day, Stanley finds a fossil of a fish, though Mr. Pendanski says that the Warden doesn't care about fossils. X-Ray, the leader of the group, tells Stanley that if he finds anything else, he needs to give it to him—he's been at camp a year and hasn't found anything. Later that afternoon, Stanley joins a circle led by Mr. Pendanski. The boys discuss what they want to do when they get out, though nobody takes it seriously. Mr. Pendanski talks about personal responsibility and calls Zero stupid.
One afternoon, Stanley finds a gold tube in the dirt with "KB" inscribed in a heart on one end. He gives it to X-Ray and suggests he wait until the next day to "find" it. The next morning, Stanley tries to ask X-Ray about the tube at breakfast, but X-Ray won't talk about it. X-Ray "finds" the tube that morning and the Warden comes out to oversee the digging. The boys spend a week digging in one area, and Stanley realizes the Warden is looking for something.
One afternoon, Zero admits to Stanley that he can't read and asks Stanley to teach him. Stanley insists he doesn't know how to teach and doesn't have the energy. The following morning, as Mr. Sir fills canteens by the holes, Magnet steals Mr. Sir's sunflower seeds. The boys pass them around, but Stanley spills the bag in his hole right as Mr. Sir returns to look for them. Stanley takes the blame, and Mr. Sir takes Stanley to speak to the Warden. In the Warden's house, the Warden paints her nails with red polish that she makes with rattlesnake venom. She hits Mr. Sir hard for bothering her. When Stanley returns to his hole, he finds that Zero had been digging for him. That afternoon, Stanley thinks about the first Stanley, who was robbed by the outlaw Kissin' Kate Barlow and left in this very desert. He apparently found refuge on "God's Thumb," though he had no idea what that even meant after he was rescued. Later, Stanley offers to teach Zero to read. They agree that Zero will dig part of Stanley's holes in exchange for lessons.
The narrator goes back to the 1880s, when the town of Green Lake was actually a lakeside town. The local schoolteacher, Miss Katherine Barlow, was beloved by all, especially Charles "Trout" Walker. Trout Walker, however, was stupid and proud of it, as well as wealthy and entitled. He was enraged when Miss Katherine turned down his advances. Not long after, Sam, the onion man, offered to fix the dilapidated schoolhouse for Miss Katherine. Over the course of a few months, Sam made the schoolhouse beautiful. Finally, they kissed in the rain one night. One person saw them and the next day, a mob burned the schoolhouse, angry because Sam was black. The sheriff wouldn't help Katherine and instead, asked her for a kiss. Katherine and Sam tried to escape across the lake, but Trout Walker shot Sam and "rescued" Katherine. Three days later, Katherine shot the sheriff, kissed him, and spent the next twenty years as a feared outlaw. She returned to Green Lake when it was a ghost town, where Trout Walker and his wife, Linda, found her. They attempted to make her give up the location of her treasure, but a yellow-spotted lizard bit her and she died laughing, telling them to start digging.
Back in the present, Mr. Sir's face swells to the size of a melon. When he delivers water, he doesn't give Stanley any. Stanley and Zero continue their reading lessons and Zero learns quickly, though the other boys mock Stanley and call him a slave master when Zero digs. Zero tells Stanley that his real name is Hector Zeroni. One morning, Stanley is able to see a rock formation in the distance that looks like a thumbs-up sign, and he wonders if it's God's Thumb. The next day, Mr. Pendanski arrives with lunch, Zigzag begins pushing Stanley and Mr. Pendanski encourages a fight. Zero rescues Stanley from Zigzag as Mr. Pendanski shoots his gun to call the Warden. Zigzag lets slip to the Warden the nature of Stanley and Zero's agreement. She insists the lessons need to stop and Mr. Pendanski insists that Zero is too stupid to learn anyway. Zero hits Mr. Pendanski across the face with a shovel and then walks into the desert. Stanley spends the next few days thinking that he should go after Zero. The Warden, Mr. Sir, and Mr. Pendanski speak to Stanley about Zero's whereabouts and say in front of him that they're going to destroy Zero's records. As a ward of the state, there's nobody to care about him.
On the day that Group D gets a new boy, Twitch, Stanley decides to steal the water truck and rescue Zero. He crashes the truck into a hole and continues on foot into the desert. He feels as though the thumbs-up sign is encouraging him. In the afternoon, he discovers Zero hiding in a tunnel under an old boat. He's been eating what he calls sploosh, which is fruit preserves of some sort. He shares his last jar with Stanley and then the two decide to head for God's Thumb. Zero begins experiencing painful episodes of stomach cramps, though he's able to walk all the way to the edge of the lakebed, climb up the cliffs on the other side, and then start up the mountain. At one point, Zero vomits and then collapses. Stanley leaves their shovel and their saved jars behind and begins to carry Zero up the hill. Close to the top, Stanley falls in a muddy gully and finds water and an onion. He gives some to Zero, and they spend the next two days recovering. Zero admits he stole Clyde Livingston's shoes from the homeless shelter, and Stanley sings him Elya's lullaby. As Zero improves, he tells Stanley about his mother. They used to live in a house, though they always had to steal. When Zero stole the shoes from the homeless shelter, he thought he was doing a better thing by stealing old shoes instead of new ones. Stanley and Zero decide to return to camp, try to dig up Kate Barlow's treasure where Stanley found the tube, and then escape.
As Stanley and Zero walk, they try not to drink water and Zero talks more about his mom. That night, they find the hole and begin digging. Stanley is surprised to discover a suitcase and is eventually able to wiggle it out. As he hands it to Zero, the Warden, Mr. Sir, and Mr. Pendanski arrive. The adults, however, back away horrified—the hole is a yellow-spotted lizard nest, and both boys are covered in lizards. Stanley and Zero are still alive hours later as the adults suggest shooting the boys to get the treasure. The Warden also runs through their story: Stanley was delusional, ran into a hole, and was killed by lizards. Stanley is too preoccupied to listen when Mr. Sir tells Stanley's he's innocent and his lawyer came to pick him up yesterday.
Finally, they see a car coming. A young woman introduces herself as Ms. Morengo, Stanley's lawyer, and introduces the Texas Attorney General. The Warden attempts to tell them that Stanley tried to steal her suitcase, but her story doesn't add up. After a few minutes, Stanley is able to crawl out of the hole and helps Zero up. When the Warden tries to take the suitcase from Zero, he points out that it has Stanley's name on it. After getting paperwork in order, Ms. Morengo tries to lead Stanley away, but he refuses to go without Zero. Ms. Morengo and the Attorney General discover that Zero's records are missing, so Ms. Morengo takes Zero with her. In the car, she explains that Stanley's father invented something to cure foot odor and pretends she didn't hear Zero's confession that he stole Clyde Livingston's shoes. It begins to rain at Green Lake.
The narrator says that whether one believes in the curse or not, it's true that Stanley's father experienced his breakthrough on the day that Elya Yelnats's great-great grandson carried Madame Zeroni's great-great-great grandson up the mountain. Camp Green Lake is slated to become a Girl Scout camp, and Stanley and Zero each get about a million dollars from the contents of the suitcase. A year and a half later, Stanley and Hector are at a party to see the new commercial for Stanley's father's invention, which Clyde Livingston promotes. Hector sits with his mother, who sings a version of the lullaby that Madame Zeroni taught Elya.