Tris is shocked by the video released by Tobias to the public at the end of the raid on Erudite headquarters. The video revealed the truth about the faction system and announced that the Divergent are needed outside the borders of the city. Factionless leader Evelyn Johnson appoints herself leader of the city, forcing people to operate under her command and live as factionless citizens. Tension between the factionless and former faction members escalates, culminating in a deadly fight over the bowls used at the faction Choosing Ceremony. Tris questions Evelyn's motives and is kidnapped by the Allegiant - a rebel group determined to escape the city and reinstate their old way of life - who invite her to a meeting the following night. Meanwhile, Tris' brother Caleb is put on trial for assisting former Erudite leader Jeanine Matthews. Caleb's betrayal, still fresh in her mind, prevents Tris from completely forgiving her brother. Tobias informs Tris that Caleb was decided to be a traitor and sentenced to be executed in two weeks. The Allegiant, led by Cara and Johanna, plan to send a group outside the city to find the truth about their existence and way of life. Tris volunteers to go on one condition: that Caleb is taken with them. Tobias and Zeke break Caleb out of his holding cell before they leave. Tobias, Tris, Christina, Cara, Uriah, Tori, Peter, and Caleb escape the city. Driving through the unknown, they meet a woman named Zoe and a man called Amar, who was Tobias' initiate instructor, and was supposedly killed for being Divergent. Zoe and Amar take the group to the Bureau of Genetic Welfare, where they meet George, Tori's brother who was also a Divergent thought to be dead. Here they learn the truth about their society: many, many years ago, the government believed that society's problems were caused by people's bad genes. In an attempt to create a better society, they began to fix people's genes with disastrous results. To fix its mistake, the government set up 'experiments', establishing isolated cities across the remains of the United States in the hopes of raising enough genetically pure (Divergent) individuals to fix the 'genetic damage' left in the wake of the Purity War. Tris and Tobias are tested by Matthew and Nita to verify and study their Divergence. While Tris is shown to be truly Divergent, Tobias' genetic structure indicates that his genes are still 'damaged'. Tobias is angered by this news and begins to believe that he is a damaged human being. Matthew then brings Tris to the leader of the Bureau, David, to find out the truth about her mother. David gives Tris her mother's journal. Meanwhile, Tobias is secretly asked to join a rebellion, led by Nita, who is also genetically damaged. She tells him that the Bureau is lying when they say genetic damage is the cause of society's problems. She intends to demonstrate that the genetically pure are flawed as well. Tobias tells Tris about the plan, going against Nita's warning to keep it secret. Tris is unsure about Nita's plans, but Tobias tells her that she’s being jealous of Nita and he agrees to help.
Shortly afterwards, Nita and her allies attack the compound, severely injuring Uriah in one of two explosions. Tris saves David from being shot by Nita and stops the attack, and then Nita is placed in prison for her crimes. After the attack, Tris confronts Tobias and temporarily ends their relationship, leaving Tobias to try not to think about the things that he has done. Tris is then offered a position on the Bureau's council and is told of the events taking place within the city, including the Allegiant's preparations for war with Evelyn and the factionless. David is desperate to stop the violence and maintain the experiment and his life's work at the expense of destroying the personalities of everyone in the city. He decides to use the memory serum to wipe the memories of the people within the city, allowing the experiment to begin with a clean slate. Tris also learns that the Bureau created the serums that led to the destruction of Abnegation and the enslaving of the Dauntless. Repulsed by the Bureau's actions and David's decision, Tris reconciles with Tobias. With her friends, she begins to create a plan to save her city and fix the Bureau's flawed ideals. The group decides to break into the Weapons Lab and use the memory serum to wipe the memories of the Bureau. The Lab is guarded by a fatal dose of the death serum, rendering it a suicide mission. Caleb volunteers for the role, and tearfully asks Tris if it will make her forgive him for everything he has done, Tris says yes. At the same time the memory serum is going to be released, Tobias, Christina, Peter, and Amar plan to go into the city to inoculate (immunize) their loved ones against the serum.
Christina is able to retrieve doses of the inoculation serum that will counteract the memory serum and tells the group to inject themselves with it. Tobias notices that Peter only pretends to inject himself with the inoculation serum. Christina gives an extra vial of the memory serum to Tobias, for use against either Marcus (his dad) or Evelyn in the hopes of bringing an end to the conflict in the city. Tobias decides to confront Evelyn. Taking Peter and the vial of memory serum, Tobias meets with his mother and gives her the option of drinking it, which will allow her to end the fighting, be born anew, and become his mother again. She embraces Tobias without taking the serum. They meet with Johanna and Marcus to iron out an end to the conflict. On the way out of Erudite headquarters, Peter laments about his bad behavior and violent tendencies which he knows will never change, and says he wants to take the memory serum to become a new person. Tobias gives Peter the serum, erasing his mind for good.
At the Bureau, Caleb is ready to sacrifice himself, but he and Tris, who accompanied him, are ambushed by Bureau guards. Tris pulls her gun on Caleb and decides to carry out the mission instead of allowing Caleb to do so, knowing that Caleb volunteered out of regret of his former actions rather than out of love for her. She hopes that her resistance to serums will include the Death variant. Not knowing if she will survive, Tris tells Caleb that if she does not return, he is supposed to tell Tobias she did not want to leave him.
Tris destroys the entrance to the Lab and is exposed to the death serum, but she survives. David came within the Lab and explains that her collusion with the genetically damaged did not go unnoticed. Determined to keep the order, David shoots Tris, who lunges for the memory serum and releases it. After being shot by David, she slowly slips into darkness until she sees her mother reach out for her and she then gladly accepts her mother's embrace, succumbing to her wounds and passing away. Tobias, Peter, and Christina return to the compound and are told about Tris' death by Cara. Caleb gives him Tris' final message. Tobias is angered by the fact that Tris died for Caleb even after his betrayal. Before walking away, Caleb only replies that Tris never wanted to leave him. Uriah is taken off life support - a decision made by Zeke and his mother - with Tobias still believing that Uriah's death was partially his fault. Tobias returns to his home in the old Abnegation sector. After cutting his hair, Tobias is ready to use the memory serum on himself, hoping to rid the loss of Tris and Uriah from his memory. Christina walks in on him and convinces him to not use it, saying that Tris would want him to remember her. Acknowledging the need to move on, Tobias and Christina walk back together.
Two and a half years later, Chicago is finally at peace, with former faction members, factionless, compound members, and other outsiders moving in and out of the city. Tobias accepts all that he has been through and reflects on his belief that while life damages everyone, and it may take time, people can always be mended.