Many Chicago citizens run towards the wall, and soldiers under Evelyn are told to shut down the perimeter, and no one is allowed through. Evelyn directs Jack Kang of Candor to hold trials for the Erudite and Dauntless conspirators, a number of them becoming executions, starting with Max. Evelyn and Johanna attempt to pressure Tris and Four into taking leadership positions in the new coalition, but both refuse. After seeing that the hostile situation within the city is only going to get worse, Tris escapes with Four, Caleb, Christina, Tori, and Peter to journey beyond the wall that encloses Chicago, although Tori is killed by Edgar in the attempt.
The group is ambushed by Edgar, who is later disabled by an armed group of individuals and airships. The soldiers take the group to the Bureau of Genetic Welfare, a highly advanced city where they learn that years ago, the government believed that society's problems were caused by "damaged genes". In an attempt to create a better society, they began to modify people's genes, with disastrous results. The government set up "experiments" in an attempt to repair this mistake, establishing isolated cities across the remains of the United States. The hope was to raise enough genetically pure Divergent individuals to fix the "genetic damage" left in the wake of the Purity War.
Tris and Four are tested by Matthew and Nita to verify and study their Divergence. Tris is shown to be truly Divergent, but Four's genetic structure indicates that his genes are still "damaged". Caleb and Peter are assigned to surveillance teams that monitor Chicago. Matthew then brings Tris to the leader of the Bureau, David. David gives Tris a device that allows her to view her mother's memories, and sees that her mother was rescued and adopted by the Bureau before volunteering to join the Chicago experiment out of dedication to the project. In return for his help in restoring peace to Chicago, Tris agrees to help David, who claims that only the council he reports to has the power to intervene.
Meanwhile, Four and Christina train with Nita and joins the Bureau's military force. They join the military on a rescue mission to a nearby wasteland village, though Four becomes mistrusting of the Bureau's intentions after realizing that they were going there to kidnap and forcefully integrate those children into the Bureau's populace. Upon their return, Four discreetly petitions Caleb to keep an eye on the situation in Chicago. Four also attempts to warn Tris of the Bureau's intentions, but she rejects his ideas.
Caleb warns Four of a rapidly escalating conflict back in Chicago between Johanna's group of Allegiants and Evelyn's factionless, with open war becoming an imminent threat. Four appeals to Tris for her to return to Chicago with him to end the bloodshed, but she decides to go with David to Providence to meet with the council. David agrees to reinsert Four back in Chicago, escorted by Matthew and some Bureau soldiers. Once in the air, Matthew quietly reveals to Four that the flight is a trap and he is meant to be killed. A skirmish breaks out and Four defeats all of the soldiers, though the airship crashes as a result. Matthew gives Four his ID card to get through the cloak wall, saying that he doesn't believe in David's work anymore and that he wants to help. Four proceeds to Chicago while Matthew remains behind to be rescued by the Bureau and warn Tris.
Meanwhile, Tris and David meet with the council. Tris disagrees with the council's objectives and criticizes how they have done nothing to stop the violence in Chicago. The council responds that David had the power to intervene whenever he desired, revealing that he had lied to her from the beginning. Tris remarks during the return flight to the Bureau that she never should have trusted him, ending their partnership. Upon her return, she gathers Caleb and Christina in David's airship to return to Chicago, and Nita aids them in escaping.
Four is captured by the factionless and confronts Evelyn to end the violence, though she shows no intention of standing down. Tris, Caleb, and Christina arrive shortly after to find the city tearing itself apart at the opening stage of a full assault by the Allegiant. David makes a deal with Peter in exchange for Peter's promotion and inserts him into Chicago to convince Evelyn to deploy a hidden Bureau stockpile of gas to wipe the memories of the attackers and force a peace in her favor, to which she reluctantly agrees. Peter takes her to a vault where she can deploy the gas across the city but remain safe herself, making her the only individual in Chicago who will remember any of those events.
Tris and Christina fight through the factionless and arrive at the vault, having rescued Four along the way. At the vault door, Four convinces Evelyn to stop the gas attack, as he wouldn't remember who she was if she carried it out. She folds and stops the release, and is shot by a frustrated Peter. Peter gloats in his victory until the same gas starts releasing inside the vault as well. Realizing David has betrayed him, Peter opens the vault so Tris and Four can stop the gas release and flees back towards the cloak wall, as Four says he will find him and make him pay for badly wounding his mother.
Caleb arrives and aids Tris in destroying the gas dispersion hub, stopping the release. The main characters gather atop the Erudite building as they watch the stolen shuttle fly back towards the Bureau, heavily laden with explosives. Tris transmits a message to the whole city, revealing to them the existence of the Bureau and that Chicago was an experiment of the Pure. Her message to the Bureau is that Chicago is no longer their experiment, but the home of its citizens. Caleb detonates the explosives at the end of the message, tearing a massive hole through the cloak wall and revealing the two cities to each other. The film ends with the Chicago characters gazing at the Bureau in the distance, with David standing behind Tris, glaring at her.