Mega Man X takes place in an unspecified time during the 22nd century (21XX) and approximately 100 years after the original Mega Man series. A human archaeologist named Dr. Cain discovers the ruins of a robotics research facility that had once been operated by the legendary robot designer Dr. Thomas Light. Among the ruins, Cain finds a large capsule which contains a highly advanced robot with human-level intelligence and emotions, and even free will; the likes of which the world has never seen before. Light had wished to instill within his creation reasonable sanity, good nature, and an understanding of the more controversial aspects of human morality. The robot was buried while running a 100-year diagnostic program to ensure these features. Cain spends the next several months studying the robot, who is named Mega Man X, or simply "X". Cain decides to duplicate X and, within several months, completes the first "replicate android" or "Reploid", a robot who can think, feel, learn, and grow exactly like a human. Within the year, the design is standardized and Reploids are mass-produced. However, with the free will given to a Reploid comes the possibility of criminal activity; such rogue Reploids are branded as "Mavericks" by law-abiding citizens.
As the public outcry against the few Maverick incidents becomes too great to deny, the government steps in, and under the advice of Dr. Cain, forms an elite military police organization called the "Maverick Hunters". The Hunters are to capture or disable any Reploids that pose a threat to humans, provide damage control at Maverick uprisings, help with disaster recovery, and perform other tasks as needed. To lead this group, Cain designs a very advanced Reploid, thought to be immune to whatever defect causes Mavericks. This robot, named Sigma, heads the Hunters some time before ultimately becoming a Maverick himself, alongside the vast majority of the other Hunters. Sigma seizes control of a small island, driving out all human occupants. Claiming that the humans are inferior and that they are limiting the growth and potential of Reploids, he calls for his followers to begin a massive extinction effort. X, guilt-ridden at having helped design such a dangerous race, joins forces with the only other remaining Hunter Zero in order to stop Sigma at any cost.
While on a mission involving a Maverick attack on a highway, X encounters Vile, a mercenary Maverick working for Sigma who pilots a mechanized tank called "Ride Armor". Unable to defeat Vile, X is saved at a critical moment by Zero, forcing Vile to retreat. Zero then offers encouragement to the less combat-savvy X after the battle. X proceeds to track down and exterminate eight of Sigma's most powerful Mavericks, then rendezvous with Zero outside Sigma's stronghold. Inside the compound, X finds that Zero has been captured by Vile. Another battle ensues, ending similar to their first meeting with X at Vile's mercy. Zero suddenly breaks free of his restraints, latches onto Vile, and self-detonates, destroying his own body and the Maverick's Ride Armor. Shocked over Zero's sacrifice, X regains his strength and finishes off Vile. Zero encourages his comrade once again, and then he dies. Now more determined than ever, X fights his way to Sigma, disables the Maverick leader, and escapes the island fortress as it explodes and sinks. As he returns to base, X reflects on the events that have unfolded, questioning Zero's sacrifice, his own decision to fight, and the ongoing war with the Mavericks.