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 very ill and eventually dies; whereafter the king believes that her spirit will return to the underworld.
In post–Civil War Spain in 1944 (after Francisco Franco has come into power), protagonist Ofelia travels with her pregnant mother Carmen to meet Captain Vidal, her new stepfather and the father of Carmen's unborn child. Vidal, the son of a famed commander who died in Morocco, believes strongly in falangism and was assigned to conquer anti-Franco rebels.
A large stick insect, which Ofelia believes to be a fairy, leads Ofelia into an ancient labyrinth; but she is stopped by Mercedes, Vidal's housekeeper, who is spying for the rebels. That night, the insect appears in Ofelia's bedroom, where it becomes a fairy and leads her through the labyrinth. There, she meets the faun, who believes her to be Princess Moanna and gives her three tasks to complete before the full moon to prove herself. Meanwhile, Vidal murders two individuals detained (incorrectly) on suspicion of cooperation with the rebels.
Ofelia completes the first task of 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 cures Carmen's illness and soothes her pain. Accompanied by three fairy guides, Ofelia then completes the second task of retrieving an ornate dagger from the lair of the Pale Man, a child-eating monster who sits silently in front of a large feast. Although she was gravely warned not to consume anything, she eats two grapes, awakening the Pale Man. He eats 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.
Vidal tortures a captive rebel, and then kills the doctor — also a rebel sympathizer — who euthanizes the prisoner. Shortly afterwards, Vidal catches Ofelia tending to the mandrake root. Carmen throws it into the fire, where it writhes and screams in agony. Carmen immediately develops painful contractions and dies giving birth to a son. Vidal discovers that Mercedes is a spy. Ofelia is locked in her bedroom, and Mercedes is taken to be tortured; however, she frees herself, injures Vidal, and rejoins the rebels.
The faun returns to Ofelia and tells her to take her baby brother into the labyrinth. Ofelia steals the baby after sedating Vidal, who pursues her through the labyrinth while the rebels successfully attack the mill at which he is stationed. The faun tells Ofelia to open the portal to the underworld by sacrifice of her brother's blood, but Ofelia refuses to harm her brother; for further disobeying his orders, the faun leaves Ofelia to her fate. Vidal, finally reaching Ofelia, takes the baby and shoots her. On leaving the labyrinth, he is captured by the rebels. Knowing that he will die, he calmly hands Mercedes the baby and demands that Mercedes tell his son the exact time of his father's death. Mercedes replies that his son will never even know his name. Mercedes's brother Pedro kills Vidal.
As Mercedes enters the labyrinth and comforts the dying girl, drops of Ofelia's blood spill onto the adjacent altar, and Ofelia appears in a golden throne room. The king of the underworld explains that the last test was a trick, to ensure that Ofelia would sooner spill her own blood over that of an innocent. The queen of the underworld, her mother, invites Ofelia to sit by her father and rule at his side. The scene then cuts back to the labyrinth, where Ofelia, smiling, passes away above the altar. The epilogue completes the tale of Princess Moanna, stating that she ruled wisely and left quiet traces of her time on earth.
- Ivana Baquero as Ofelia / Princess Moanna, a child who comes to believe she is the reincarnation of a fairy princess. Del Toro said he was nervous about casting the lead role, and that finding the 10-year-old Spanish actress was purely accidental. (The film was shot from June–October 2005, when she was 11). "The character I wrote was initially younger, about 8 or 9, and Ivana came in and she was a little older than the character, with this curly hair which I never imagined the girl having. But I loved her first reading, my wife was crying and the camera woman was crying after her reading and I knew hands down Ivana was the best actress that had shown up, yet I knew that I needed to change the screenplay to accommodate her age."Baquero says that Del Toro sent her lots of comics and fairy tales to help her "get more into the atmosphere of Ofelia and more into what she felt". She says she thought the film was "marvelous", and that "at the same time it can bring you pain, and sadness, and scariness, and happiness".
- Sergi López as Captain Vidal, Ofelia's new stepfather and a Falange officer. Del Toro met with López in Barcelona, a year and a half before filming began, to ask him to play Vidal. In Spain, López was considered a melodramatic or comedic actor, and the producers told Del Toro "You should be very careful because you don't know about these things because you're Mexican, but this guy is not going to be able to deliver the performance"; del Toro replied "Well, it's not that I don't know, it's that I don't care". Of his character, López said: "He is the most evil character I've ever played in my career. It is impossible to improve upon it; the character is so solid and so well written. Vidal is deranged, a psychopath who is impossible to defend. Even though his father's personality marked his existence — and is certainly one of the reasons for his mental disorder — that cannot be an excuse. It would seem to be very cynical to use that to justify or explain his cruel and cowardly acts. I think it is great that the film does not consider any justification of fascism."
- Maribel Verdú as Mercedes, Vidal's housekeeper. Del Toro selected Verdú to play the compassionate revolutionary because he "saw a sadness in her ... he thought would be perfect for the part".
- Doug Jones as the Faun and the Pale Man. As the Faun, Jones guides Ofelia to the fantasy world. As the Pale Man, he plays a grotesque monster with an appetite for children. Jones had previously worked with del Toro on Mimic and Hellboy, and said the director sent him an email saying, "You must be in this film. No one else can play this part but you". Jones responded enthusiastically to an English translation of the script, but then found out the film was in Spanish, which he did not speak. Jones says he was "terrified" and del Toro suggested learning the script phonetically, but Jones rejected this, preferring to learn the words himself. He said, "I really, really buckled down and committed myself to learning that word for word and I got the pronunciation semi-right before I even went in", using the five hours a day he spent getting the costume and make-up on to practice the words. Del Toro later decided to dub Jones with the voice of Pablo Adán, "an authoritative theatre actor", but Jones's efforts remained valuable because the voice actor was able to match his delivery with Jones's mouth movements.Jones's dual casting is intended to suggest that the Pale Man (along with the toad) is either a creation of the Faun, or the Faun himself in another form.
- Ariadna Gil as Carmen / Queen of the Underworld, Ofelia's mother and Vidal's wife.
- Álex Angulo as Doctor Ferreiro, a doctor in the service of Vidal, but an anti-Francoist. He is shot by Vidal after exposure thereof.
- Manolo Solo as Garcés, one of Vidal's lieutenants.
- César Vea as Serrano, one of Vidal's lieutenants.
- Roger Casamajor as Pedro, Mercedes' brother and one of the rebels.
- Federico Luppi as King of the Underworld, Ofelia's father
- Pablo Adán as Narrator / Voice of Faun
The idea for Pan's Labyrinth came from Guillermo del Toro's notebooks, which he says are filled with "doodles, ideas, drawings and plot bits". He had been keeping these notebooks for twenty years. At one point during production, he left the notebook in a taxi in London and was distraught, but the cabbie returned it to him two days later. Though he originally wrote a story about a pregnant woman who falls in love with a faun, Sergi López said that del Toro described the final version of the plot a year and a half before filming. Lopez said that "for two hours and a half he explained to me all the movie, but with all the details, it was incredible, and when he finished I said, 'You have a script?' He said, 'No, nothing is written'". López agreed to act in the movie and received the script one year later; he said that "it was exactly the same, it was incredible. In his little head he had all the history with a lot of little detail, a lot of characters, like now when you look at the movie, it was exactly what he had in his head".Ofelia with a fairy.
Del Toro got the idea of the faun from childhood experiences with "lucid dreaming". He stated on The Charlie Rose Show that every midnight, he would wake up, and a faun would gradually step out from behind the grandfather's clock. Originally, the faun was supposed to be a classic half-man, half-goat faun fraught with beauty. But in the end, the faun was altered into a goat-faced creature almost completely made out of earth, moss, vines, and tree bark. He became a mysterious, semi-suspicious relic who gave both the impression of trustworthiness and many signs that warn someone to never confide in him at all.
Del Toro has said the film has strong connections in theme to The Devil's Backbone and should be seen as an informal sequel dealing with some of the issues raised there. Fernando Tielve and Íñigo Garcés, who played the protagonists of The Devil's Backbone, make cameo appearances as unnamed guerrilla soldiers in Pan's Labyrinth. Some of the other works he drew on for inspiration include Lewis Carroll's Alice books, Jorge Luis Borges' Ficciones, Arthur Machen's The Great God Pan and The White People, Lord Dunsany's The Blessing of Pan, Algernon Blackwood's Pan's Garden and Francisco Goya's works. In 2004, del Toro said: "Pan is an original story. Some of my favourite writers (Borges, Blackwood, Machen, Dunsany) have explored the figure of the god Pan and the symbol of the labyrinth. These are things that I find very compelling and I am trying to mix them and play with them." It was also influenced by the illustrations of Arthur Rackham.
Del Toro wanted to include a fairy tale about a dragon for Ofelia to narrate to her unborn brother. The tale involved the dragon, named Varanium Silex, who guarded a mountain surrounded by thorns, but at its peak is a blue rose that can grant immortality. The dragon and the thorns ward off many men though, who decide it is better to avoid pain than to be given immortality. Although the scene was thematically important, it was cut short for budget reasons.
There are differing ideas about the film's religious influences. Del Toro himself has said that he considers Pan's Labyrinth "a truly profane film, a layman's riff on Catholic dogma", but that his friend Alejandro González Iñárritu described it as "a truly Catholic film". Del Toro's explanation is "once a Catholic, always a Catholic".
In regards to whether or not the fantasy underworld was real or a product of Ofelia's imagination, del Toro stated in an interview that, while he believes it is real, the movie "should tell something different to everyone. It should be a matter of personal discussion". He then mentioned there were several clues in the movie indicating the underworld was indeed real.
The film was shot in a Scots Pine forest situated in the Guadarrama mountain range, Central Spain. Guillermo Navarro, the director of photography, said that "after doing work in Hollywood on other movies and with other directors, working in our original language in different scenery brings me back to the original reasons I wanted to make movies, which is basically to tell stories with complete freedom and to let the visuals really contribute to the telling of the story".