In an unnamed European town, children go to a candy shop after school. Charlie Bucket, whose family is poor, can only stare through the window as the shop owner sings "The Candy Man". The newsagent for whom Charlie works after school gives him his weekly pay, which Charlie uses to buy a loaf of bread. On his way home, he passes Willy Wonka's chocolate factory. A mysterious tinker recites the first lines of William Allingham's poem "The Fairies", and tells Charlie, "Nobody ever goes in, and nobody ever comes out." Charlie rushes home to his widowed mother and his four bedridden grandparents. After he tells Grandpa Joe about the tinker, Joe tells him that Wonka locked the factory because other candy makers, including his arch-rival, Arthur Slugworth sent in spies disguised as employees to steal his chocolate and candy recipes. Wonka disappeared, but three years later began selling more candy; the origin of Wonka's labor force is a mystery.
Wonka announces to the world that he has hidden five "Golden Tickets" in his chocolate Wonka Bars. The finders of these tickets will be given a tour of his factory and a lifetime supply of chocolate. Four of the tickets are found by Augustus Gloop, a gluttonous German boy; Veruca Salt, a spoiled British girl; Violet Beauregarde, a gum-chewing American girl; and Mike Teavee, a television-obsessed American boy. As each winner is heralded to the world on TV, a sinister-looking man whispers to them. Then, the fifth ticket is found by a millionaire in Paraguay, South America, much to the dismay of Charlie and his family.
The next day, Charlie finds money in a gutter and uses it to buy a Wonka Bar. After eating it, he uses the change that he has left to buy another bar for his Grandpa Joe. At that time, the newspapers reveal that the Paraguayan millionaire had forged a ticket, and when Charlie opens the Wonka bar, he finds the real fifth golden ticket. Racing home, he is confronted by the sinister man seen whispering to the other winners. After Charlie gasps from fright, the man introduces himself as Slugworth and offers to pay him for a sample of Wonka's latest creation, the Everlasting Gobstopper.
Charlie returns home with his news. Grandpa Joe is so elated that he finds he can walk, and so Charlie chooses him as his chaperon. The next day, Wonka greets the ticket winners at the factory gates. Each is required to sign an extensive contract before they may begin the tour. The factory is a psychedelic wonderland that includes a river of chocolate, edible mushrooms, lickable wallpaper, and other marvelous inventions. Wonka's workers are beings known as Oompa-Loompas.
During the tour, Augustus falls into the Chocolate River and is sucked up a pipe to the Fudge Room. Violet blows up as a blueberry after chewing an experimental three-course meal gum, against Wonka's warnings. The group reaches the Fizzy Lifting Drinks Room, where Charlie and Grandpa Joe disregard Wonka's warning and sample the drinks on purpose, only to break the rules and get in trouble. They are not caught in the act, but have a near-fatal encounter with an exhaust fan. Veruca demands a goose that lays golden chocolate eggs, which leads her to singing "I Want It Now", and then falling down the garbage chute leading to the furnace. Her father shortly falls in trying to rescue her. Mike then succumbs to the lure of "Wonkavision", which teleports Mike but leaves him only six inches tall. All of this misbehavior has Oompa Loompas singing about their bad conduct.
After Augustus' demise, Wonka gives the remaining ticket winners an Everlasting Gobstopper on the condition that they never talk about or show them to anyone. At the end of the tour, only Charlie and Grandpa Joe remain, but Wonka dismisses them, without awarding them the promised lifetime supply of chocolate. Grandpa Joe follows Wonka to ask him about this, and Wonka angrily tells him that because they had violated the contract by stealing Fizzy Lifting Drinks, they receive nothing. Seeking revenge, Grandpa Joe suggests to Charlie that he should give Slugworth the Gobstopper, but Charlie cannot bring himself to intentionally hurt Wonka and returns the candy back to him instead.
Wonka immediately changes his tone, and declares Charlie the winner. He reveals that "Slugworth" is actually his employee named Mr. Wilkinson, and the offer to buy the Gobstopper, as well as his rant, was a test: Charlie was the only one who passed. The trio enter the "Wonkavator", a multi-directional glass elevator that flies out of the factory. Soaring over the city, Wonka reveals to Charlie that his actual prize is the entire factory itself because Wonka had created the contest to find an honest child worthy enough to be his heir. He informs that Charlie and his family can move into the factory immediately.