King Kandy convinces Ralph (John C. Reilly) that Vanellope (Sarah Silverman) can't be allowed to race, because she's a mere "glitch," a mistake character who wasn't really supposed to be part of the game. If she's allowed to race, children playing the game will see that she fades in and out, everyone will believe that the game machine is defective, and the game may be shut down for good.
Sadly, Ralph smashes the car he and Vanellope built together, and returns to the Fix-It Felix Junior game where he normally lives. From there, he sees the Sugar Rush machine, and realizes that Vanellope's picture appears prominently on the machine. She wasn't a mistake at all- she was actually supposed to be the primary character of that game. King Kandy lied to him- but why?
Ralph returns to the world of Sugar Rush, and learns the truth: King Kandy is actually Turbo, a character from an old car-racing video game. Turbo had re-rigged the machine to make himself the KIng of Sugar Rush world, and to make everone forget that Vanellope was the true princess of that world. After Ralph left, Turbo had Vanellope and Fix-It Felix imprsioned in the dungeon.
Ralph breaks Felix out of the dungeon, and gets Felix to fix Vanellope's broken car. Vanellope joins the big car race, and is vying with Turbo for the lead, when Turbo is swallowed by the giant alien bug that Ralph accidentally brought to Sugar Rush world from the "Heroes' Duty" video game. Vanellope is about to win the race when thousands of baby alien bugs attack Sugar Rush world. Everyone in SUgar Rush world begins to evacuate the game- once they're out, Sgt. Calhoun (Jane Lynch) plans to blow up the exit so the bugs can't ever invade the other video game worlds.
Ralph has another idea- he goes to the Diet Coke Mountain and pounds the Mentos roof. He wants to make all the Mentos fall into the underground Diet Coke lake, creating a gigantic geyser of scalding hot liquid. He hopes all the alien bugs would be attracted to the geyser and be killed by it. But suddenly, a giant mutant bug appears- it's a hybrid of the first alien bug and Turbo, whom she swallowed. The Turbo bug picks up Ralph and flies high nto the sky with him. Ralph breaks free and falls doento the MEntos roof. He knocks all the Mentos into the Diet Coke, and all the bugs (inbcluding Turbo) are killed by the geyser.
Vanellope is able to finish the race, which causes the game machine to reset. Everyone in Sugar Rush world now remembers that Vanellope was the pricess, and is sorry for the way they treated her.
Ralph goes back to the Fix-It Felix Junior game, and doesn't mind being the bad guy any more. All the other characters in the game start to treat Ralph more kindly now. Ralph even manages to help characters from defunct video games (like Q-bert) get jobs working in the Fix-It Felix game.
Meanwhile, during their adventures together in Sugar Rush world, Sgt. Calhoun and Felix ahve fallen in love. They get married, with Ralph as best man.
Thanks John L!