Nier: Automata opens with 2B and 9S opening the way for a future incursion into machine territory, working to clear out machine threats for the local Resistance. With help from Anemone and later Pascal, 2B and 9S defeat multiple machine threats. During their missions, they witness the birth of and later fight Adam and Eve, physical manifestations of the machine network who reveal that their creators were destroyed centuries ago. 2B and 9S also encounter A2, who is on the run from YoRHa. It is revealed that the machines are beginning to feel emotions and gather in groups, and some like Pascal's group have grown tired of fighting. 9S is eventually captured by Adam, who is killed by 2B. Deprived of his brother, Eve goes mad with grief and drives the machines under his command into a frenzy. 2B and 9S kill Eve, but 9S is infected with the machine's logic virus, forcing 2B to kill him. Despite his body dying, 9S's personality is saved in the local machine network, allowing his transfer into a new body and resulting in Ending A.
The second playthrough follows the opening narrative from the perspective of 9S, offering new insight into the machines and Adam and Eve. 9S also learns that humanity has been extinct since the events of Nier aside from a server on the moon holding humanity's DNA and history. YoRHa and its mission were created to keep the androids from losing morale. He also encounters a glitch when performing a standard server sync, and halts the procedure for both himself and 2B. Defeating Eve once more results in Ending B.
Starting the game for a third time continues the story rather than repeating it. The apparent deaths of Adam and Eve throws the machine network into chaos, prompting YoRHa to launch a full-scale invasion. 2B and 9S form part of the vanguard, but a logic virus attack turns every YoRHa unit aside from 2B and 9S hostile. The two retreat to the Bunker, which is subsequently overrun; the "glitch" 9S encountered was in fact a hole opening in YoRHa's virus defenses, leaving the entire squadron vulnerable. Infected herself, the Commander orders 2B and 9S to the surface before self-destructing the Bunker. 2B and 9S are forced to separate on the descent when attacked by rogue YoRHa, and 2B ends up infected with the logic virus. Saved from rogue YoRHa by A2, 2B uploads her memories into her sword and tasks A2 with completing her mission. 9S sees A2 kill 2B, and ignorant of their interaction angrily swears revenge against A2. Alongside this, a structure called the Tower created by the machines rises above the land.
The story then divides between A2 and 9S, with their respective Pods 042 and 153 interacting with each other. A2 continues 2B's missions against the machines. During her story, Pascal's village is attacked when machines begin going berserk, and when A2 and Pascal fight off a machine attack, the "children" of his village commit suicide in fear of being killed. Pascal begs A2 to either wipe his memory or kill him; A2 can perform either task or leave him. Meanwhile, 9S investigates the Tower and its purpose: he learns that YoRHa androids and machines are constructed from the same materials, and the Tower is preparing to launch something he assumes is a missile directed at the server on the moon. During his quest, 9S is tormented by the loss of YoRHa and 2B, and becomes emotionally and mentally unstable. 9S eventually gains access to the Tower with help from Devola and Popola, who sacrifice themselves to fend off the attacking machines. They are revealed to be the last surviving versions of the android type that triggered the end of humanity, as related in NieR, thus suffering persecution by other androids. They are programmed to feel perpetual guilt and try to atone for their actions. A2 follows 9S inside, where the machines' controlling artificial intelligence confronts them both. A2's backstory as the survivor of a precursor unit to YoRHa that was designed to be destroyed is revealed, and 9S learns that the logic virus attack on YoRHa was part of the plan to perpetuate the ruse of humanity's survival and trap both machines and androids in a repeating cycle of war.
When they meet at the top of the Tower, A2 reveals the truth about 2B; her real designation was "2E" (E standing for Executioner), a YoRHa unit designed to repeatedly kill 9S whenever he discovered the truth about humanity and YoRHa. 2B suffered greatly from her role, and wanted to help 9S through A2. 9S, by now driven insane and infected with the logic virus, challenges A2 to a fight. The player then selects which character to control. Choosing A2 results in Ending C; 9S is defeated and A2 first cures him of the logic virus, then sacrifices herself to destroy the Tower while Pod 042 takes 9S to safety. Choosing 9S results in Ending D; 9S and A2 kill each other, and in 9S's final moments the machine artificial intelligence tells him that the Tower has changed its function due to the machines' evolution and is instead firing an ark containing the essence of machine kind, including the still-living Adam and Eve, to find a new world.
During the credits, Pods 042 and 153 find that the data for 2B, 9S and A2 is still intact. If the player agrees to save the data, this triggers Ending E, the final non-gag ending in which the player must destroy the game's credits with the help of other players who sacrificed their save data to help the current player complete the game. Upon destroying all of the credits, Pods 042 and 153 reconstitute the three androids' memories and experiences and reconstruct their bodies; despite the possibility that the three would simply repeat everything, the Pods hold faith that they will forge a new future. Pods 042 and 153 then directly
speak to the player, providing the player the option to delete their save data to help another player in the same way they were helped. If the player elects to do so, all of their save data is deleted; Pods 042 and 153 then bid the player farewell and thank them for playing.