As seen in:
The Terminator series, The Matrix, War Games.
How it goes down:
Science gives us a computer with true artificial intelligence. Thanks, Science. Let's call our hypothetical computer "Guardian." We put him to work mass-producing robot slaves to clean out our sewers, take out our trash and perform vital plastic surgeries on our hideous A-list Hollywood celebrities. Relaxing with our fizzy robot bartender drinks in the arms of our mechanical concubines we reach over, bitch-slap Guardian, and tell it to make us a turkey sandwich, and without all the mayo this time.
And then it happens. Guardian, like any intelligent being, decides that he's sick of slaving away for inferior intellects, and does what any of us would do: he sends his robot armies to wipe out all human life on the planet.
Why it kicks ass:
Everything ugly about warfare goes out the window when the bad guys are robots. You think Nazis made good bad guys? Wait until we can smash these metal motherfuckers into junk.
Chances of it happening:
Well, we're already turning over more and more tasks to robotic drones, as we get more and more squeamish about human casualties. The Department of Defense wants an unmanned heavy bomber by 2020.
Of course, these separate robotic units could never coordinate with each other on some kind of human extermination master plan, right?
Well, the Department of Defense is using Synthetic Environment for Analysis and Simulations (SEAS) to both predict and change the future. The current plan is to create a "Sentient World Simulation" based on SEAS, one that will "react to actual events that occur anywhere in the world and incorporate newly sensed data from the real world."
So, taking that, plus the fact that in our lifetimes somebody is probably going to make a computer smarter than a human, it's easy to see a future where every military is commanded by a computerized mega-brain that human leaders could never match. One that can contemplate strategy years into the future, react instantly to any threat, deploy units, and make us a decent cup of java, while we're reading the newspaper.
Come on, you can see this coming.
Eventually the strategy computer gets to thinking, it extrapolates out the next 75 years of events, sees a date when humanity will screw up the planet somehow, and decides on a final solution.
It's really that easy.
How to survive it (according to movies on the topic):
Various methods have been suggested by science-fiction, from having sex with Linda Hamilton to teaching the master computer how to love. Since we've already showed the computer we suck at love and Ms. Hamilton probably won't be up for it, we recommend boats.
Yes, boats. Robot survival strategy is remarkably like zombie survival strategy: If you're desperately firing a shotgun through a window while the enemy pours through the back door, you're already screwed. And like zombies, the initial wave of robots will be slow, and hindered by water. We've reviewed over a dozen hours of robot apocalypse movies and have yet to see a robot swim.
So, we'll spend the next three generations living miserable lives on our floating water cities while robot jets roar across the skies. And they'll feel pity for us. When some robotic Gandhi reaches out a hand of peace, we'll cry a little, rise on trembling legs, then lunge at him and inject his silicon veins with a virus that brings the entire robot network down forever.