The androids' support pods (042 and 153) gain consciousness and refuse to delete the protagonists' data. Through a collective effort of the player and the community, the pods reconstruct 2B, 9S, and A2, giving them a chance to live in a world free from the cycle of war—provided they don't repeat the same mistakes.
For more details on the deep lore and character backstories, you can explore the NieR:Automata Wiki .
A massive white structure called rises from the earth, acting as a launchpad for the Machines' final plan. 9S and A2 converge at the top. While A2 seeks to destroy the network to end the cycle, 9S only wants to destroy everything out of grief.
The androids were given a fake god (humanity) to fight for so they wouldn't lose the will to live.