Legend is set in a future flooded, fortified Los Angeles, ruled by the totalitarian Republic. The novel centers around Day and June, two 15-year-olds on opposite sides of the economic spectrum. June Iparis is a military prodigy, born into an elite family, and groomed for success in the Republic's highest circles. She is the only person to have ever scored full marks on the Trial, a comprehensive test administered at age 10 to determine the child's future role in society. Her parents died several years before the start of the story, so she is raised by her older brother Metias. Daniel "Day" Wing is an infamous wanted criminal, born in the impoverished slums of the Republic. His family believes he is dead, apart from his older brother John.
Day learns that his younger brother, Eden, is infected with the Plague, a disease that periodically ravages sectors of the Republic. Day breaks into the city hospital to steal medicine and escapes after a confrontation with Metias. Later that night, June is informed by Thomas, an officer in the Republic and Metias's childhood friend, that her brother is dead and that Day is the killer. June graduates early from her military university and sets out to catch Day. Using the promise of a cure for Eden's infection, she lures Day to the site of one of his previous heist locations, and they converse, albeit not face-to-face before Day realizes she is a Republic agent and June infers his home sector by recognizing his accent.
June witnesses the interrogation of a spy from the Colonies, another North American country in perpetual war with the Republic. She is appalled by the violent beating delivered by Thomas. June poses as a street urchin and goes searching for Day. She gets in a street fight, stepping in for a young girl named Tess, and beats the previous champion, Kaede. June is stabbed in the process. Day rescues June, unaware of her identity, and Tess, a friend of Day's, sets about healing June. Day and June begin to develop romantic feelings for each other, but June realizes who he is and reports his family's location to Thomas and the Republic. Day attempts to defend his family's house from Republic soldiers, but Thomas kills his mother and Day is captured by June's commanding officer, Commander Jameson. Thomas congratulates a horrified June on a job well done.
June questions Day on his long list of crimes; Day insists he is innocent of Metias's murder. June reviews Day's files and discovers he got a perfect score on the Trial, like June herself. However, instead of Day being celebrated as a prodigy, the Republic falsified records to indicate Day failed his Trial and died in a labor camp. While Day is being moved to a new cell, he sees evidence that the Republic is intentionally spreading the Plague. Day is further tortured by Commander Jameson and sentenced to death.
June informs Day that John is in a cell and Eden has been sent to labs on the war front. Day tells June about painful tests inflicted on him after supposedly failing the Trial. Children sent to "work camps" are actually killed or used for experimentation in laboratories; Day escaped after being left for dead. Day tells June his theory about the origins of the Plague. Later, protestors gather in support of Day; June watches Thomas order his soldiers to fire on the protestors.
Day is interrogated by Thomas and learns that Kaede, the girl beaten in a street fight by June, is a Patriot spy; the Patriots are a rebel group connected with the Colonies. That night, June determines that Metias was actually murdered by Thomas, under the orders of Commander Jameson. Metias left a coded message for June, revealing that their parents were murdered for discovering the true purposes of the Plague: a method of culling the weaker Republic populations, and a biological weapon against the Colonies. Day learns that Eden was the index case for a new Plague strain. June decides to break Day and John out, and she goes to meet with Kaede to strike a deal with the Patriots.
June and the Patriots plot an escape plan, but Jameson moves up the execution date. June attempts to rescue Day and John on her own but is arrested by Thomas. Their confrontation is halted by attacking Patriots, and June escapes with Day in the chaos; John sacrifices himself to allow June and Day to escape, and the Republic, having mistaken John for Day, claims that Day has been executed. Day and June decide to head to the war front labs to rescue Eden and then escape into the Colonies.