Weiss, you dumbass! SPOILER ALERT - Plot details for NIER follow.
Nier is the playable character in the prologue and later the primary antagonist of Nier Replicant, who is the leader of the Shades. He first appears at the end of the first half of the game and serves as the antagonist for the remainder of the game. He is known as the Shadowlord throughout the main game.
It is revealed that Nier and Yonah took part in the Gestalt experiment prior to the prologue, but Nier grew suspicious of the project and the potential dangers of the Gestalt process. This led him to take Yonah with him and escape the facility, leading to the events of the prologue.
"Stay away from my sister!"
In the end, it is revealed that the Shadowlord is actually the original Nier, who was the player character in the beginning of the game. In the year 2053, 50 years after the incident where the The Dragon and the The Giant appeared in Tokyo, Nier and Yonah (as real humans) were trapped in Shinjuku district when its lock down commenced. Nier sought help for Yonah's growing disease from a charity organization's center that supposedly handed out food and medicine for the survivors. Instead he, along with 12 other people, received a clone of the Grimoire Noir. The charity was actually a human experimentation site designed to find the "original Gestalt," who can keep his own consciousness even after going through the "Gestalt process." When Nier saw the fellow survivors turn into crazed, relapsed Gestalts, he escaped with Yonah and sought refuge in a supermarket. The relapsed Gestalts found them though and Nier was forced to turn to the black book so he could fight them off. Yonah presumably touched the grimoire to help Nier, but this caused her to start to relapse. During the 1,412 time skip between the prologue and the main game, Nier's soul was separated from his body as part of Project Gestalt and this bodiless shade is later named Shadowlord.
Just like the Replicant Nier (the character played as throughout most of the game), Shadowlord's ultimate goal is to not only save his sister, whose soul (or Shade) needs the body of Replicant Yonah, but save humanity (the Shades).
As the first sentient Gestalt, the organization behind Project Gestalt offered to put the Gestalt Yonah into hibernation until she could return to her Replicant body in return for Nier (now in his "Shadowlord" form) helping them create stabilized Gestalts. Because of this, all the sentient Shades are linked to Shadowlord and his death would cause them to relapse.
In the end, Gestalt Nier realized that the Gestalt Yonah's relapsing couldn't be stopped and he kidnapped the Replicant Yonah to return her to her body. This set to motion the Replicant Nier's quest for vengeance.
"Yonah...I cannot live...in a world without you..."
—Nier as the Shadowlord
The Shadowlord makes his first in-game appearance as his new form when Nier's village is assaulted by Shades. Using the diversion of the titanous Knave of Hearts, the Shadowlord infiltrated the village library with the intent to kidnap the Replicant Yonah hiding inside, as she was key to rescuing his own Gestalt Yonah from her relapse.
Nier fought his way into the library, seemingly defeating the giant shade, but was ambushed by the Shadowlord. The Gestalt impaled Nier through his shoulder, critically wounding him. It was then revealed that the Shadowlord was already in possession of Yonah's comatose body, and he was planning to leave when Nier and Grimoire Weiss recovered from the surprise attack. Despite their best efforts, the two were distracted by the Shadowlord's own magic book, Grimoire Noir, who held the two back and allowed his master to escape victorious. The Gestalt and the Black Book then fled, leaving the heroes to face what remained of the seemingly immortal Knave of Hearts that was now inside the Library with them.
That is why you, the YoRHa forces, exist: SPOILER ALERT - Plot details for NieR: Automata follow.
It is revealed in NieR: Automata that as a result of Nier dying, the human race eventually went extinct, due to the Gestalts relapsing and the Replicants dying from either the Black Scrawl or natural causes. This event led to the creation of YoRHa, the operation that would perpetuate the lie that humanity was still alive and on the moon.
It is also stated that the machines psychological development was a result of the remnants of Project Gestalt's data being uploaded to the network, including the data of the original Gestalt: Nier.