Nier: Automata (Japanese: ニーア オートマタ Hepburn: Nīa Ōtomata, stylized as NieR:Automata) is an action role-playing video game developed by PlatinumGames and published by Square Enix for PlayStation 4 and Microsoft Windows. The game was released in Japan in February 2017, and worldwide the following month. Nier: Automata is a sequel to the 2010 video game Nier, a spin-off of the Drakengard series. Set in the midst of a proxy war between machines created by otherworldly invaders and the remnants of humanity, the story follows the battles of a combat android, her companion, and a fugitive prototype.

Nier: Automata shares the post-apocalyptic setting of the original Nier, taking place after the game's fourth ending. While carrying over the Drakengard series' tradition of a dark atmosphere and branching storylines, no direct narrative connection is shared between Nier: Automata and the rest of the series. Set an unknown time after the events of Nier, the story revolves around a war between the remnants of humanity and the machine army of invaders from another world. The initial invasion forced humanity to flee to the Moon.

Humanity eventually sends down combat androids dubbed "YoRHa" to fight the invaders in a proxy war. While denied emotions and lacking true names, they have particular attitudes that distinguish them from their fellows. The YoRHa are commanded from the Bunker, a reconnaissance base in orbit above Earth, and establish a self-sufficient Resistance on Earth to drive back the Machines.

The main protagonist is YoRHa No. 2 Model B, or "2B" for short, a female-model YoRHa android whose main traits are being calm and composed. She is accompanied by "9S" (YoRHa No. 9 Model S), a reconnaissance android who displays more emotion than other YoRHa units; and observed by "A2" (YoRHa Model A No. 2), an obsolete prototype android of 2B's line with a taciturn personality who often chooses to act alone.

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. 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.

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 then self-destructs the Bunker.

2B and 9S are forced to separate on the descent when attacked by rogue YoRHa, and 2B ends up infected with a 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 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.

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, thus suffering persecution by other androids and programmed to feel perpetual guilt and 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 the 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", 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.

In the third ending, should the player choose A2, 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. In the fourth ending, should the player pick 9S, the two kill each other, and in his 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 speak to the player upon finding that the data for 2B, 9S and A2 are still intact. If the player agrees to save the data, this triggers the fifth ending: Pods 042 and 153 reconstitute the 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.

NieR: Automata tells the story of androids 2B, 9S and A2 and their battle to reclaim the machine-driven dystopia overrun by powerful machines.