Master director Pedro Almodovar teaches a stunning lesson on sexuality and identity in his new film, “Bad Education,” a wonderful if troubled work touched by the director’s passion. The lurid and the ugly meet the beautiful within the complicated but unavoidably fascinating film.

In “Law of Desire”, the filmmaker’s 1987 classic, a transsexual woman revisits the priest who molested her as a child. “Education” revisits the same narrative, but replaces its campy irreverence with a darker, more mature introspection. By using the conventions of film noir and melodrama to produce a network of complex and gritty stories, he takes the viewer on an unforgettable and shocking ride that would leave the Pope shaking in his seat. Though the film sports the craftiness of film noir, it breaks every mold of the genre, making a man its femme fatale and using two young boys in its central love story.

The plot is organized around a man, Ignacio, who has become a woman after years of reflecting on his childhood love affair with his 10-year-old Catholic school peer, Enrique. After a credit sequence reminiscent of Hitchcock’s “Vertigo,” the movie travels to the office of Enrique (Fele Martinez), now a successful director who is so desperate for ideas that he scours the tabloids, hoping to steal inspiration.

The door opens, and in walks a man who claims to be Ignacio (Gael Garcia Bernal), with a screenplay in tow. The audience is immediately aligned with Enrique, who becomes a spectator himself while reading the script.

Almodovar transports the viewer inside the screenplay’s story, which details the boys’ love story. Astoundingly, they vie for each other’s attention while constantly attempting to escape the pedophile Father Manolo, (who, to complicate things further, Ignacio’s transsexual counterpart will later decide to confront and blackmail.)

Back in the world of reality, Enrique decides to produce his friend’s work, overcome by its dynamism. But, like the general narrative of “Education,” things are never so easy — especially in an Almodovar film.

Unbeknownst to Enrique and the audience, there happens to be a far more compelling story behind the script than mere artistic expression. In an attempt to understand what has truly inspired Ignacio to pitch this screenplay, Enrique — like many of the other men throughout the film — ends up going to a darker place than expected.

Almodovar’s stories can never be summarized without losing some of their power, which come from atmosphere, music, organic visual effects, and cinematic detail.

The film is aesthetically lovely, filled with powerful darks and colorful lights. Yet this gives way to diffused, luminescent cinematography during the schoolyard scenes, a section whose beauty is at odds with the ugliness and controversy of pedophilia. Almodovar shows uncharacteristic restraint during these scenes, pulling the camera back, but showing just enough to make the viewer squirm. He also avoids moralizing, depicting the priest with humanity and even sympathy, revealing a man passionately obsessed and twisted by desire.

Passion, the main thrust of Almodovar’s films, is what makes the often-unlikeable character of “Bad Education” so complicated and interesting.

Nonetheless, the film sometimes struggles with its complexity. In the process of depicting such layered characters, along with an already intricate plot and its sensitive subject matter, it often overburdens and overwhelms the viewer. Almodovar repeatedly recurs to melodramatic cliches and cheesy camera tricks to make his subtle points more obvious. The film within a film also comes off as a bit gimmicky.

But the talented cast is able to handle the movie’s complications with finesse, bringing the sometimes far flung narrative back down to earth. Garcia Bernal stands out in this respect: The actor admirably takes on the incredibly difficult roles of Ignacio and Sahara — a mesmerizing transvestite with a pout that puts Julia Roberts to shame. The actor is at once a sexy femme fatal and a masculine seducer, a fragile young boy, and a calculating deviant.

“Bad Education” may not be the easiest movie to watch, but compelling films rarely are. Almodovar’s many fans will not be disappointed.