A prisoner named Finn has escaped from Incarceron, a mechanical prison that has become a living entity. Finn left behind his friend Keiro and a slave girl he rescued, Attia.
Finn promised Attia and Keiro he would return for them. Believing Finn went back on his promise, Attia has been searching for a way out of Incarceron. She follows leads about Sapphique, the only person to ever escape Incarceron before Finn, but only finds a sideshow run by a man named Rix. Rix is known by his stage name, the Dark Enchanter.
Rix claims to have Sapphique's glove, a magical object that Attia hopes will help her escape. She joins Rix's show, hoping to find the glove. As the troupe travels to another town, thieves set upon them. Rix begs their leader not to take the glove, telling him it's only a prop, but the leader ignores him. After he puts on the glove and his hand begins to burn, Attia discovers that the glove was fake and filled with acid.
While the thug is wearing the glove, Incarceron, the living prison, uses the thug to write a message to Attia. The prison tells her that it will soon see the stars, but stars are only found in the Realm. The troupe moves on to a village in a frozen wing of the prison. During that night's show, the villagers attack Rix and try to take the glove.
Attia realizes that the villagers have the plague. The people hope the glove can save them. She escapes with Rix but is stopped by Keiro, whom Attia has been working with. Attia discovered earlier that Rix keeps the real glove in a pouch around his neck, so she takes the glove and rides off with Keiro.
The world outside Incarceron is known as the Realm. The Realm lives under strict rules known as Protocol, which keep the people from using technology. They live in a medieval society. Finn has spent his two months in the Realm coming to terms with the idea that he is Prince Giles, the heir. But Finn has few memories of his life before Incarceron and cannot prove that he is the prince. He is uncomfortable in the stuffy world of royal politics and misses Keiro.
Claudia, Giles' intended and the daughter of Incarceron's warden, and Jared, Claudia's tutor, want Finn to become king and put an end to Protocol. They are working to fix the portal into Incarceron so they can rescue Keiro, Attia and the warden.
When Claudia encounters her father's secretary Medlicote, he reveals that he and her father are part of the Steel Wolves, a rebel group trying to do away with Protocol. She tells him that Finn wants the same thing and the rebels should back the prince.
Jared meets with Queen Sia. She insists that he stop fixing the portal and offers to give him access to the Academy, the place where all the technology and research from before Protocol is stored. Jared is suffering from an illness that will eventually take his life, and Queen Sia tells him he might find answers in the Academy.
Inside Incarceron, Attia and Keiro flee the plague town. When they're far enough away, they stop and make camp. During the night, a monster made of bodies and metal comes upon them. Keiro kills the bodies, but the fight leaves the two stranded on ice in the middle of a melting lake. While stranded, Incarceron speaks to them. It reveals that it's trying to escape to the Realm and has everything it needs except for Sapphique's glove.
Attia knows that if Incarceron is able to leave, all the prisoners who rely on it will die. Incarceron promises to help them escape the lake as long as they bring it the glove. Attia thinks it's a bad idea, but Keiro agrees. The prison builds a mechanical road to lead them to its heart, the place where it wants them to bring the glove.
Back in the Realm, the court holds a ceremony to publically announce that Finn is Prince Giles. At the end of the announcement, the people are asked if any oppose Finn's claim. A boy contests it, saying that he is Prince Giles. In light of the boy's knowledge of Giles' life, the queen decides that there will be an official hearing to determining which boy is the prince.
Jared, Claudia and Finn go to the portal room to discuss the pretender in private. While there, the portal begins to work. The warden speaks to them from inside the prison. He tells them that when Sapphique wore the glove, he and Incarceron became one. Sapphique's visions of the Realm infected Incarceron with a desire to see the outside world. He tells them of the prison's plans to create a body and escape.
Inside Incarceron, Attia and Keiro are following Incarceron's path. During the journey, Attia thinks she hears someone calling her name. She and Keiro follow the sound off the path and into a hidden room that looks like a nursery filled with toys. They discover a music box that allows them to communicate with the outside. Jared is working on the portal, trying to fix it before he leaves for the Academy.
They all share the information they have about Incarceron's plan. Before Attia can tell them about the glove, Incarceron speaks to her and Keiro through a toy puppet in the nursery. The prison believes they've betrayed it, but Keiro promises that he will still bring Incarceron the glove.
In the morning, Finn and Claudia escort Jared into the forest and say goodbye as he continues on to the Academy. On their way back, they are attacked. They escape and are helped by some passing commoners. When they return to the castle, they discover that there's been a fire and the portal is destroyed.
Claudia thinks the queen started the fire to prevent them from rescuing the warden. Claudia tells Medlicote that she believes he and the Steel Wolves were the ones who attacked her and Finn, but Medlicote denies it. He reminds her that the warden had a portal in his study at their home. They can use it to bring the warden, Attia and Keiro out of Incarceron.
At the Academy, Jared researches Incarceron. He discovers many files about the prison and an emergency exit located in the prison's heart. He downloads the files onto a disk. Learning that he hasn't followed her orders to leave the Incarceron matter alone, the queen sends a man to assassinate Jared. Jared escapes and begins to travel to Claudia's home, but his illness grows worse. On the journey, he collapses and has delusions that he is speaking with Sapphique.
Attia and Keiro continue following Incarceron's path. As they are crossing a bridge suspended high above the ground, a gang of women captures them. The women take the glove from Keiro and are going to kill him until Attia convinces them not to. They imprison Keiro while trying to convince Attia to join them. One woman tells Attia that they are working for the prison. She reveals that they've been following the warden's orders, and the warden is helping Incarceron. Attia then speaks to the warden through a communication device, promising to bring him the glove if he has the women release Keiro. The warden agrees.
When Attia has the glove, she throws it from a home that is suspended above the prison like the bridge. Keiro jumps after the glove and manages to grab it before it disappears. He and Attia make it to the ground and discover Rix waiting for them. He places a spell on them to fall asleep.
Back in the Realm, Finn and the pretender are questioned in front of the queen and the Council, a group of royal men. The pretender has all the right information and also provides witnesses attesting that he is Giles. The Council says they will give their final judgment the next day.
In the meantime, the queen orders everyone to attend her masked ball that night. Claudia has discovered that if Finn is found to be false, she will be killed with him. Knowing the Council will name the pretender as Giles, she plans for them to escape during the ball. When the Council members arrive at the party, Claudia realizes that the queen means to have them announce their verdict immediately, rather than wait for the next day.
She and Finn escape but are followed by the pretender. He and Finn have a standoff, and the pretender is shot in the arm. He reveals that he was paid by the queen to play the part of Giles. Finn and Claudia escape and head to her home, the Wardenry.
In the prison, Attia and Keiro wake to find they are tied up. Rix has gone mad. He tells them that he is Sapphique and plans to kill Attia for taking the glove. Before he can hurt her, Keiro asks Rix one of the riddles from the legend of Sapphique. Earlier, Rix had told Attia that he would accept a person as an apprentice if that person spoke the magic words to him. Because the riddle is the magic phrase, Keiro becomes Rix's apprentice. The three travel toward the prison's heart where they will give the glove to Incarceron, but the warden takes them prisoner before leading them there.
In the Realm, Finn and Claudia journey to the Wardenry, and Finn begins to remember his life as Prince Giles. They reach the Wardenry and begin to prepare to defend it from the imminent attack by the queen. When the queen and her army arrive, she threatens to attack if Finn doesn't surrender by morning.
Meanwhile, Jared is on his way to the Wardenry, but the queen's son, Caspar, finds him. Medlicote and a group of Steel Wolves show up and prevent Caspar from killing Jared. They take Caspar prisoner, but Jared convinces the Steel Wolves to keep the boy alive. Jared knows a secret way into the Wardenry, and he believes they can prevent the battle if Caspar is their prisoner. The Steel Wolves agree. Medlicote, Jared and Caspar sneak into the Wardenry.
Finn and Claudia try to figure out how to use the portal in the Wardenry so they can bring the warden back, but are unsuccessful. They hear voices coming from the portal. Inside Incarceron, Rix, the warden, Keiro and Attia are in the prison's heart. They see the body the prison has made for itself. It looks like a statue of Sapphique. After Keiro gets the glove, he threatens to put it on if Incarceron doesn't promise to take him out of the prison. Before he can do that, he disappears, and Claudia appears in his place.
In the Realm, Keiro arrives in the portal room just as Jared arrives with Caspar. Keiro still has the glove. When the queen's soldiers fire a warning shot, announcing that Finn's time is up, Finn and Keiro take Caspar to the castle wall so the soldiers can see their prince in enemy hands. The queen sends soldiers through Jared's secret passage, which her men discovered. But as Finn orders the secret passage sealed off, the Realm suddenly changes. Everything that was once opulent and beautiful is decaying and ugly, and they learn that everything in the Realm was an illusion created by holograms. The holograms have stopped working because Incarceron is gathering all the energy it can to make its escape. Finn discovers that the queen has been using technology to keep herself young. Without any power left, she cannot sustain her youthful body, so she dies. Her death makes Finn king and puts an end to any potential battles.
In Incarceron, the prison is furious that Keiro disappeared with the glove. It begins to make everything freeze in an attempt to punish Attia, Rix and the warden. The warden says that if Incarceron shows him the emergency exit Sapphique escaped through, he'll get the glove and bring it back. The prison wants the glove before it will reveal the exit. Before they can come to an agreement, a group of rioting prisoners arrive. They are in a panic because the prison has been shutting itself down in an effort to concentrate all its power on its escape plan. The warden tries to calm them down, but they keep rioting until Incarceron threatens to kill them. In an effort to stop the prison from escaping, the warden contacts Medlicote and instructs him to destroy the glove.
Jared makes Claudia promise not to destroy the body the prison built. He has a plan that requires the body and the glove. After Finn, Keiro and Jared make the dangerous trek through the decaying house back to the portal room, Jared locks himself inside to prevent Finn from thwarting his plan.
In Incarceron, Rix begins a magic show for the rioters. When he asks for a volunteer willing to have their deepest fears revealed, the prison volunteers. While Rix is doing his show in the prison, Jared is communicating with the prison from the Realm. After he tells the prison that he is Sapphique, he puts on the glove and is transported into the prison where he inhabits the body that Incarceron built. Wearing the glove connects Jared's mind to Incarceron so he can plan to bring the prison under order and make it the utopia it was always meant to be. He opens the portal between Incarceron and the Realm, intending to keep it open so people may come and go as they please.
Claudia, Attia and the warden join Keiro and Finn in the Realm. With all the power from the Realm gone, they are back in an authentic medieval time. Finn promises to be done with the protocol that has enslaved the Realm in the past. He and his friends set out to learn how to survive in their new world that is truly without technology.