Tris, Four, Caleb, Peter, and Marcus travel to Amity, where several surviving Abnegation have settled. Amity issues a statement that all factions may seek a place of safety there offering refuge as long as they reside in peace.
Erudite and Dauntless traitors arrive at Amity to search for Abnegation members. Tris, Four (Tobias), and Caleb escape by jumping onto an oncoming train full of armed factionless, including former Dauntless initiate Edward,who escorts them to a factionless-safe zone. The group is lead to factionless leader, Four's mother, Evelyn, who was believed to be dead. Tris overhears a conversation between Four and Evelyn, during which Evelyn tells Four that he needs to convince the Dauntless to join the factionless. During this encounter, Evelyn threatens Tris. Caleb moves to a safe zone where more Abnegation are living while Tris and Four travel to Candor headquarters.
When they reached Candor, Tris and Four are arrested and subjected to a truth serum trial at Candor. During the trial, Four admits he joined Dauntless to escape his father's abuse. He intended to leave Dauntless to be factionless after this last group of initiates, but saw Tris and decided to protect her. Tris admits shooting Will which angers Four and Christina, who were unaware she was Will's killer.
Candor is attacked by Dauntless traitors led by Eric. The victims are shot with a new simulation serum. Tris and Uriah are revealed as Divergent. They discover what is happening and attempt to warn the remaining Divergent, but are captured by Eric. His orders from Jeanine are to take two Divergent back to Erudite headquarters and execute the rest. Tris injures Eric as Dauntless burst into the room and take control. They realize the new serum allows Jeanine to subject victims to simulations from great distances. The serum doesn't wear off and gives Erudite much greater control over their victims. After the attack, Candor leader Jack arranges a meeting with Erudite that is secretly observed by Tris, Four, Lynn, and Shauna. Erudite, represented by Dauntless traitor Max, demands that Candor turn over Eric, Divergents, and a list of everyone who didn't receive the new serum injection. Tris realizes Jeanine is controlling Max via earpiece and must be near, but Lynn shoots Max from her secret location before Tris can act. Tris, Four, Lynn, and Shauna attempt to escape the Dauntless traitors but run into Jeanine and her guards. Peter, who is among the guards, allows them to escape. Shauna is shot and paralyzed as they flee.
Back at Candor, Four confronts Tris about her recklessness, and says they're finished if she continues in this manner. Dauntless holds a secret meeting, and Four, Tori, and Harrison are elected as new leaders. They put Eric on trial for his crimes. He is convicted and Eric demands execution from Four, who complies. Dauntless return to their headquarters, and Tris and Four head for a meeting with Evelyn and Edward. On the way, Four tells Tris that one of the fears in his landscape changed. Instead of having to shoot a woman, he has to watch Tris die. At the meeting, Four makes an agreement with the factionless to destroy Erudite and establish a new government. Tris believes Evelyn abandoned Four to his father's abuse and doesn't trust her.
That night, Christina and Tris discover a simulation that causes Dauntless members to step off the roof every two days unless a Divergent is surrendered to Erudite. They save a young girl and Lynn's brother, Hector, but Marlene plunges to her death. Tris, overcome by grief and guilt, flees the funeral. Christina finds her and forgives her for what happened with Will because the simulations place a person under complete control from Jeanine. Tris goes to Four's room, intent on sacrificing herself to Erudite. He begs her to reconsider, and she agrees, but leaves for Erudite at midnight while he sleeps.
Tris walks into Erudite headquarters and agrees to Jeanine's testing as long as the results are explained to her. She is subjected to an MRI and several simulations. She sees Caleb, who is now working for Jeanine, and is shocked at his betrayal. One evening, Tris encounters Four in the hallway, and discovers he tried to save her. They are taken to the execution chamber, where Jeanine injects Tris with a terror-inducing drug to force Four to reveal where the factionless safe houses are located. Jeanine is unable to find a simulation that will control Tris. She loses her temper and the two have an altercation. She declares Tris will die the next day, but Peter, her executioner, decides to repay her for saving his life. He helps Tris and Four escape.
The three travel to the Abnegation sector, where the factionless and Dauntless have gathered. Four leads Tris to his house after Evelyn kicks Marcus out, and they admit their love for each other. Greatly affected by her near-death experience, Tris wanders her old neighborhood. She bumps into Marcus, who convinces Tris that her parents died to save information that Jeanine stole. He insists this information must be made public before the Dauntless/factionless army destroy all data in their attack. Under disguise, Tris, Christina, and Marcus infiltrate Amity to update Amity leader Johanna and ask for her help. She holds a meeting to inform the rest of Amity and Amity decides to remain impartial. Johanna and several others choose to leave the faction. Tris and Christina speak with Erudite refugees living in Amity, including Will's sister Cara. Cara agrees to help with the mission to save the stolen information and transmit it to all factions.
Tris travels back to the city and leads a group disguised as Erudite to infiltrate the faction headquarters. They get inside and Cara begins connecting computers to transmit the data to other factions. After an encounter with Caleb, Tris and Marcus realize the data won't be on the main computer. Tris, Marcus, and Christina head up to Jeanine's private laboratory after Tris remembers what Tori mentioned about security. They run into Edward on the way. After a fight disables Edward and Christina, Tris and Marcus reach an intersection. They split up and go into two different doorways. Tris enters a simulation that forces her to fight herself. Tris, more desperate than her simulation counterpart, forces the simulation to give her a gun. She faces her guilt over Will and kills her simulation-self. When she walks into the laboratory, she finds Tori screaming at Jeanine to acknowledge her brother, a Divergent, who was killed on Jeanine's command. Tris disarms Tori, and after a struggle, attempts to explain that she doesn't want Tori to kill Jeanine so they can obtain information from her computer. Tori refuses and kills Jeanine by stabbing her in the stomach.
Tori calls Tris a traitor and attempts to have her taken into custody, while Four confronts her about aligning with Marcus. Uriah escorts Tris downstairs. As they reach the holding area for the surviving Erudite, Candor, and Dauntless, they find an injured Lynn, and comfort her as she dies. Evelyn announces the institution of a new factionless government and society. Dauntless begins to protest but find themselves powerless since their weapons were taken by the factionless. Caleb, Marcus, and Four enter the room. Four and Tris kiss and reconcile, and Tris hopes all the secrets between them are gone for good. Screens in the room begin to play the information retrieved by Four and Caleb, an old video featuring a woman named Amanda Ritter. Ritter was from an organization fighting for justice and peace who later took the identity of Edith Prior. Amanda vaguely explains that the world had become corrupt (due to reasons revealed in the next novel, Allegiant). The city was sealed away from the rest of the world until the Divergent increase numbers. Then Amity will open the fence forever and the population should re-enter the world. As the video ends, the room erupts into voices.