NOTE: This spoiler was submitted by Jeremy.
A young man waits at a train station holding a stack of papers. A pretty young woman stands near him and smiles. The wind blows a piece of paper into her face. He apologetically removes it, and she giggles at she's left some lipstick on it. She boards the train and the man sadly watches her leave. At work, he bemoans his loss as his boss piles more paper on his desk. He looks out the window and sees the woman in the building across the street. He throws a paper airplane to get her attention, but it falls. He continues trying but never gets her attention. He runs out of paper and uses the paper with her lipstick. It fails to reach her. The boss puts more paper on his desk and looks at him as if to say "Stop fooling around and get back to work." The man defiantly runs out the building and tries to catch up to the woman as she leaves her building, but she is gone. Defeated, he walks away, throwing away the last paper airplane. Suddenly, that paper airplane comes to a pile of other paper airplanes, which all rise and seem to fly on their own. They surround the man as the lipstick paper flies to the woman. Eventually, the paper airplanes reunite the man and woman at the train station. They end up going on a date to a coffee shop, laughing and having a good time.
Wreck-It Ralph (John C. Reilly) talks about his life in a nutshell - as part of his role in the game Fix-It Felix Jr, his home is moved to the dump and replaced by a complex full of people known as Nicelanders. Unhappy about this, Ralph smashes and wrecks the building, so the game's hero, Fix-It Felix (Jack McBrayer) comes to repair the damage with his magic hammer. When the game is over, Felix gets a medal, and the Nicelanders throw Ralph off the building into a pile of mud. As the arcade closes overnight and he goes home to his pile of bricks, he watches Felix receive admiration and wonders how it must be nice to be a hero.
We see Ralph is at a meeting for video game villains - Bad Anon - headed by Clyde the Ghost in the Pac Man game and featuring other famous bad guys like Bowser, Dr. Robotnik, and Zangief. Despite Ralph's desire to not be a bad guy, the others tell him that it's essentially their job to be bad, but that doesn't mean they themselves are bad for doing so. They close the meeting with a bad guy oath - "I am bad, and that's good. I will never be good, and that's not bad. I will always be me."
The villains leave Pac Man and go to Game Central Station, where other video game characters travel from game to game. Ralph comes across Q-Bert, whose game was unplugged, rendering him homeless. He gives him a big cherry he picked up in Pac Man and goes back to his game.
The Nicelanders are throwing a 30th anniversary party for Felix, where even Pac Man is present. Ralph decides to join the party, but he comes in and makes a mess. Felix is nice to him, but the Nicelanders look upon Ralph with scorn. When they bring out a cake featuring the characters on the building with Felix front and center and Ralph at the bottom growling, he tries to place himself at the top as one of the Nicelanders, Gene, keeps egging him on. Ralph wants a medal like Felix, but Gene asserts that bad guys like him don't get medals. He sets out to prove him wrong.
Ralph goes to Tapper, a bar for video game characters and comes across a panicky soldier from Hero's Duty, a relatively new game. He tells Ralph only the bravest and baddest are allowed there, and he decides he wants to go as the soldier mentions that the winner gets a medal. He screams at the sight of a bug and knocks himself unconscious. Ralph takes his armor and heads back to Game Central Station and into Hero's Duty.
As the arcade opens the next day, a girl comes in to play Hero's Duty. It's a first person shooter game led by Sgt. Calhoun (Jane Lynch), a tough-as-nails, no-nonsense woman. They are facing the Cy-Bugs, which transform into whatever they eat. As the game begins, Ralph is unable to control the gun and nearly gets attacked by the Cy-Bug, then interferes with the first person shooter, causing the girl in the arcade to lose. Calhoun chastises him for his interference as they restart. Ralph doesn't want to restart and seeks the medal himself.
The girl tries to play Sugar Rush, a candy-themed racing game, but two boys won't let her. She goes to play Fix-It Felix Jr, but Ralph is missing. She reports this to Mr. Litwak (Ed O'Neill),, the arcade owner, who places an "out of order" sign on the game. In the game, Felix and the Nicelanders panic, thinking they are going to be unplugged. Felix thinks Ralph is just late, and as a wagon pulls in from the station, Q-Bert comes out. After talking to Felix, they determine that Ralph has "gone Turbo" (important later).
Back in Hero's Duty, Ralph climbs a tower where he finds the medal. He feels proud as holographic soldiers congratulate him, but he steps on a Cy-Bug egg, causing it to crack open and attack him. They stumble into a pod that launches itself from the tower. At the same time, Felix enters the game and is nearly attacked by Calhoun and her men. Felix is immediately smitten by Calhoun and explains he is looking for Ralph, just as the pod zooms past them and they see Ralph and the Cy-Bug.
The pod flies all around the station until it crashes into Sugar Rush, ejecting Ralph and the Cy-Bug. The creature falls into a gooey purple swamp while Ralph tries to get the medal back from a candy tree. There, he meets Vanellope Von Schweetz (Sarah Silverman), a little girl character. She annoys Ralph and swipes the medal as he falls from a tree into a taffy swamp. As she walks away, she flickers.
Vanellope goes to the racetrack where the Sugar Rush racers are meeting to see who will play for the daily race. King Candy (Alan Tudyk), the game's ruler and top racer, goes first, followed by the others who place their tokes in there for a chance to race. Vanellope uses Ralph's medal, and she is recognized by the other racers as a glitch. Before they can race off, Ralph comes in looking like a candy-coated monster. Candy gets his donut and eclair officers to arrest him.
Meanwhile, Felix and Calhoun are at the station as Calhoun sets off to find and destroy the Cy-Bug. One of her men tells Felix that she was programmed with the most tragic backstory - on her wedding day, she forgot to do a perimeter check, and her fiancé was eaten by a Cy-Bug, which she promptly destroyed. Felix decides to join her to find Ralph because he knows he can be a valuable asset to her. She lets him join, and they go off on her hover board.
Back in Sugar Rush, Ralph is brought before King Candy, who recognizes him. After Ralph tells his story, Candy decides to throw him in the dungeon, but Ralph escapes. Elsewhere, Vanellope finds the other racers and shows off a cart she made herself (it's crappy). The other racers, led by Taffyta Muttonfudge (Mindy Kaling) break the cart, saying she can't race because she's a glitch. Ralph sees this and scares off the other racers. He demands his medal back, but she's already used it. They decide to help each other - if he helps her make another cart, she'll try and get his medal back, since the two of them both want their lives changed for the better.
They go to a baking factory that literally bakes a new kart. Ralph clumsily adds all the ingredients to make an odd-looking kart, but Vanellope loves it. At that moment, Candy and his men storm in and try to get them. Ralph shoots them with glaze and tries to get Vanellope to drive, but she can't. They escape anyway and eventually come to Vanellope's hideout, which is located behind sugar-free lollipops and is in a bonus level that is a hot cola volcano that has Mentos hanging over them. If any of them fall, naturally, it causes a slight eruption (also important later). Vanellope laments that the other racers think she is a mistake, so to prove them wrong, Ralph creates a track where they practice racing.
Meanwhile, as Felix and Calhoun arrive, she can't locate the Cy-Bug. Felix mentions he hopes Ralph hasn't "gone Turbo". When Calhoun asks, Felix tells how there was a racing game featuring Turbo, a popular racer. When a new racing game was introduced, Turbo game-jumped to that game and interfered with the program, effectively putting the new game and his own out of order and eventually unplugged. Just then, Felix and Calhoun fall into Nesquik-sand (quicksand made from chocolate milk powder, if you couldn't tell). As Felix panics, Calhoun slaps him, causing some Laffy Taffy to descend and laugh. She continues slapping him to get them to laugh, and he pulls her and himself out of there. Calhoun then appears to be falling for Felix after this act of bravery, but then comes to her senses and continues moving, unaware that the Cy-Bug is beneath them, eating candy and morphing into a candy-coated version of itself.
Candy's men come back and haven't found Ralph or Vanellope. He sends them back out and goes into a room where the game's code is. He takes out the Hero's Duty medal from there and removes Vanellope's name from the racing board.
Ralph and Vanellope set out to the race off with the new kart, but she goes back to get something. Just then, Candy rides in and gives Ralph his medal. Ralph is suspicious, but Candy tells him that Vanellope cannot race because she is a glitch, and if she does race, she will be picked by a player, and as she flickers, they will think the game is out of order, forcing Litwak to unplug the game, and since Vanellope cannot leave a game, being a glitch, if the game is unplugged, she will die with the rest of the program. Candy leaves, and as Vanellope comes back, she presents Ralph with a cookie medal she made, saying "You're my hero." However, Ralph says he cannot let her race for her own good after speaking to Candy. He puts her up in a tree, and he regretfully smashes her kart to pieces, causing her to cry and say he really is a bad guy.
Felix and Calhoun fly over the land as he dreamily stares at her, calling her a "dynamite gal". This triggers a memory in her where he fiancé would call her that even right before he was eaten. She forcibly kicks him out of her jet. Felix sadly goes to Candy's castle where he tells Candy's right hand man, Sour Bill, he is looking for Ralph. Bill responds by dropping Felix down to the dungeon.
Ralph goes back to Fix-It Felix Jr, but the penthouse is empty, save for Gene, who leaves Ralph with the key to the place. Ralph sees the "out of order" sign from the game's window and tosses his medal at the window, which causes the sign to fall slightly. From there, he sees Sugar Rush and sees Vanellope's face on the side of the console.
He goes back to Sugar Rush and finds Sour Bill. He interrogates him, and Bill reveals that Vanellope and Felix are locked in the dungeon, and that Candy changed Vanellope's code so that she would become a glitch, but he also reprogrammed the memory of the rest of the Sugar Rush inhabitants.
Calhoun continues her search for the Cy-Bug, but she falls underground and sees that the creature has multiplied and it's eggs are hatching.
Ralph busts Felix out of the dungeon, but Felix is mad at Ralph for what he's done. Ralph tells Felix he just wanted to be loved and respected for once, and so he piles up the broken kart pieces he picked up and has Felix fix it with his hammer. He presents Vanellope with the restored kart and apologizes to her.
They make it to the racetrack for the race off, and Vanellope zooms past the other players, including Taffyta and her friends. As she catches up to Candy, Calhoun catches up with Ralph and Felix and warns them about the Cy-Bugs just as they burst from the ground. She fights them off and orders the other characters to head to Game Central Station.
As Vanellope gets past Candy, he tries to attack her, but she holds onto him and causes him to flicker as well, making him change into a completely different character. On the screen, Ralph and Felix recognize him as Turbo, and he reveals to Vanellope that he reprogrammed the entire game in his favor. She glitches one more time to get out of the cave, just as Candy/Turbo rolls into the mouth of a Cy-Bug.
Calhoun gets the others out of the game and continues fighting off the Cy-Bug army, but she runs out of ammo. Ralph takes Vanellope out before she reaches the finish line and tries to get her out, but she is unable to. Calhoun says they can't defeat the bugs because the game has no beacon like in Hero's Duty. Ralph then gets the idea to activate the hot cola geyser and flies off on Calhoun's hover board. He starts smashing the Mentos for them to fall in, but he gets hit by a creature, which turns out to be the Cy-Bug that ate Candy/Turbo, and is now a monstrous hybrid of the villains. He grabs Ralph and forces him to watch the bugs almost kill Vanellope, but he releases himself and plunges from a great height as he recites the bad guy oath once more before completely smashing the Mentos barrier. The geyser erupts into an explosion of bright hot cola, drawing the bugs to the light. Even Candy/Turbo is unable to move away from the light, causing him, and the rest of the Cy-Bugs to be incinerated. Vanellope glitches her way to save Ralph, and they land in a chocolate river. Felix gives Calhoun a peck on the cheek in his joy. But she grabs him and gives him a full on kiss.
Felix fixes the racetrack, and Ralph helps Vanellope cross the finish line. As she does so, she turns into a princess, and the memory of the Sugar Rush characters is restored. Turns out Vanellope was always the rightful ruler of Sugar Rush, and she is no longer a glitch. She ditches the princess outfit and decides to be democratic as the other racers apologize for their cruelty toward her. She and Ralph hug as they part ways.
Ralph goes back to his game as Mr. Litwak happily sees the game is fully functioning. Ralph goes back to a Bad Anon meeting and tells the other bad guys he is taking life "one game at a time." He also tells what happened to the rest of the characters - the homeless video game characters like Q-Bert have been added to Fix-It Felix Jr as part of a bonus level where they help Ralph wreck the place. Felix and Calhoun get married, with Ralph as the best man and the other Hero's Duty soldiers making sure no Cy-Bugs are present. The other Nicelanders have warmed up to Ralph and appreciate him being there. Finally, Vanellope has become popular with other players for her ability to glitch past other racers. At the end of their games as Ralph is getting thrown off the roof and Vanellope wins a race, they see each other through their windows and give each other a smile and wave. Ralph concludes by deciding "If that kid likes me, how bad can I be?"