Prior to the events of the film, a scientist is ordered by his dictator to create a machine in the apparent name of progress. The Scientist uses his own intellect to create the B.R.A.I.N., a thinking robot. However, the dictator quickly seizes it and integrates it into the Fabrication Machine, an armature that can construct an army of war machines to destroy the dictator's enemies. Lacking a soul, the Fabrication Machine became corrupted and pursues one goal: to exterminate all life on Earth. The Fabrication Machine reprograms the other war machines to turn against humans by using toxic gas and chemical weapons. On the verge of destruction, the Scientist uses alchemy to create nine homunculus-like rag dolls known as "Stitchpunks" using portions of his own soul via a talisman, but dies upon finishing the last one.
Sometime later the last doll, 9, awakens in the Scientist's workshop. Taking the talisman with him, 9 ventures out into the devastated city and meets 2, a frail inventor who gives him a voice box and is surprised when 9 reveals the talisman. The last surviving machine, the Cat-Beast, attacks the pair and kidnaps 2 and the talisman. 9 collapses, but awakens in Sanctuary, a cathedral that is home to the other dolls, including the dogmatic leader 1, his large bodyguard 8, the cyclops engineer 5, and the mentally unstable oracle 6. 1 immediately labels 2 as dead, but 9, having seen the factory where the Cat-Beast has taken 2, decides to rescue him. 9 and 5 venture to the factory where they find 2. 7, the only female of the dolls, arrives and slays the Cat-Beast, but 9, drawn by curiosity, foolishly puts the talisman into the previously derelict Fabrication Machine, causing 2's soul to be absorbed by the machine, reviving it and killing him in the process; 9, 5 and 7 manage to escape the factory.
7 takes 9 and 5 to the library, where the silent scholar twins, 3 and 4, show 9 the Fabrication Machine's origins. 5 realizes the talisman's symbols match the clairvoyant drawings of 6. 9 and 5 return to Sanctuary to investigate, but 1 confronts and chastises them. The Fabrication Machine starts constructing new machines, one of which, the bird-like Winged Beast, attacks Sanctuary and leading to a battle between the dolls and the Winged Beast, 7 sneaks behind it for a sneak attack, but it notices and punches her aside. 7 tries it again but her right leg is injured by the Winged Beast's tail lance. 5 and 6 zoom up a derelict plane with wires and the Beast is killed by the propeller. Retreating to the library with 1 saddened by the loss of his home, 5 sews 7's injured leg, 6, 3, and 4 cryptically explain the talisman's origins, but 1 once again chastises the group. As 9 found out that 1 sent 2 to die, 7 tries to attack 1 but 9 stopped her and so 7 runs away. The Fabrication Machine meanwhile has made many Spiderbots, small spider-like robots, and Seekers, hot-air balloon-like robots. The Fabrication Machine, angered at the loss of the Winged Beast, finds 2's corpse and uses it as a hypnotic lure for another robot, the Seamstress. The Seamstress attacks the library and 7 and 8 are captured in the resulting battle, but the body of 2 is safely recovered and given a funeral by the others. The others then run to the factory to destroy the machines. 9 goes inside alone, kills the Seamstress, and rescues 7, but is too late to save 8, as the Fabrication Machine already absorbed his soul. Afterwards, 9 and 7 escape while the others destroy the factory by pushing an oil barrel with a flaming rag fuse into a puddle of oil, pulling a Seeker with it.
The dolls celebrate but 5, as he goes to try and retrieve a disk for the phonograph they're playing, discovers the Fabrication Machine is still alive. He shouts a warning to the others as he tries to escape it, however, the Fabrication Machine captures him and absorbs his soul. The remaining dolls run across an unstable bridge where 6 tells 9 that the others are trapped within the machine and that they shouldn't destroy it. 6 convinces 9 to return to the "first room" (the Scientist's workshop) to gain answers. The bridge collapses and the Fabrication Machine grabs 6 and absorbs his soul. 9 follows 6's instructions, finding a holographic recorded message from his creator, who reveals that the "Stitchpunks" he created are all apart of himself including 9, making them the only hope for humanity. He then explains that the talisman can be used against the Fabrication Machine and free the dolls' souls trapped in it. 9 reunites with the other dolls, willing to sacrifice himself so 7 can get the talisman since it was he who started this. However, 1, having had a change of heart, puts himself in the way and is killed instead allowing 9 to remove the talisman and destroy the Fabrication Machine, freeing the trapped souls. 9, 7, 3 and 4 free the souls of 5, 1, 6, 2 and 8 from the talisman, who fly up into the sky causing it to rain. The final image shows that the raindrops contain small flecks of glowing bacteria, bringing life back to the world.