In a fairy tale, Princess Moanna, whose father is the king of the underworld, visits the human world, where the sunlight blinds her and erases her memory. She becomes mortal and dies. The king believes that eventually, her spirit will return to the underworld, so he builds labyrinths (which act as portals) around the world in preparation for her return.
In 1944 Francoist Spain, Ofelia travels with her pregnant but sickly mother Carmen to meet Captain Vidal, her new stepfather. Vidal, the son of a famed commander who died in Morocco, believes strongly in Falangism and has been assigned to hunt down republican rebels. A large stick insect, which Ofelia believes to be a fairy, leads Ofelia into an ancient stone labyrinth, but she is stopped by Vidal's housekeeper Mercedes, who is secretly supporting her brother Pedro and other rebels. That night, the insect appears in Ofelia's bedroom, where it transforms into a fairy and leads her through the labyrinth. There, she meets the faun, who believes she is the reincarnation of Princess Moanna. He gives her a book and tells her she will find in it three tasks to complete in order for her to acquire immortality and return to her kingdom.
Ofelia completes the first task — retrieving a key from the belly of a giant toad — but becomes worried about her mother, whose condition is worsening. The faun gives Ofelia a mandrake root, which seems to ease Carmen's illness. Accompanied by three fairy guides, Ofelia then completes the second task — retrieving a dagger from the lair of the Pale Man, a child-eating monster. Although she was warned not to consume anything there, she eats two grapes, awakening the Pale Man. He devours two of the fairies and chases Ofelia, but she manages to escape. Infuriated at her disobedience, the faun refuses to give Ofelia the third task. During this time, Ofelia quickly becomes aware of Vidal's ruthlessness in the course of hunting down the rebels. After he erroneously murders two local farmers detained on suspicion of aiding the rebels, Vidal interrogates and tortures a captive rebel. He asks Doctor Ferreiro to tend to the captive, whom Ferreiro then proceeds to surreptitiously euthanize at the rebel's own urging. Vidal realises that Ferreiro is a rebel collaborator and kills him. Vidal later catches Ofelia tending to the mandrake root, which he considers delusional. Carmen agrees and throws the root into the fire. She immediately develops painful contractions and dies giving birth to Vidal's son.
Mercedes, having been discovered to be a spy, tries to escape with Ofelia, but they are caught. Ofelia, mistaken as a traitor, is locked in her bedroom, while Mercedes is taken to be interrogated and tortured. Mercedes frees herself, stabs Vidal, and rejoins the rebels. The faun, having changed his mind about giving Ofelia a chance to perform the third task, returns and tells her to bring her baby brother into the labyrinth to complete it. Ofelia complies and Vidal pursues her as the rebels launch an attack on the outpost. Ofelia meets the faun at the centre of the labyrinth. The faun suggests drawing a few drops of the baby's blood, as completing the third task and opening the portal to the underworld requires the blood of an innocent. As Ofelia refuses to harm her brother, Vidal finds her talking to the faun, whom he cannot see. The faun leaves, and Vidal takes the baby from Ofelia's arms before shooting her.
Vidal returns to the labyrinth's entrance, where he runs into Mercedes and Pedro along with the other rebels. Knowing that he will be killed, he hands the baby to Mercedes and asks that she tell his son the exact time of his father's death. However, Mercedes refuses, telling him "He won't even know your name", and Vidal is then shot to death by Pedro. Mercedes enters the labyrinth and comforts a motionless but breathing Ofelia. Drops of Ofelia's blood fall down the centre of the spiral stone staircase onto an altar. Ofelia, well dressed and uninjured, then appears in a golden throne room. The King of the underworld says that she passed the final test, which was to choose to spill her own blood rather than that of an innocent. The faun praises Ofelia for her choice, addressing her once more as "Your Highness". The Queen of the underworld, her mother, invites Ofelia to sit next to her father and rule at his side. Back in the stone labyrinth, Ofelia smiles as she dies peacefully in Mercedes' arms.
The epilogue completes the tale of Princess Moanna, stating that she ruled wisely and left quiet traces of her time in the human realm "visible only to those who know where to look."