“Harry Potter and the Prisoner of Azkaban” (2004), third in the hugely successful series of Warner Bros. films based on the J.K. Rowling novels, was the last to feature an original score by composer John Williams — who so memorably established the main themes in the first film, “Harry Potter and the Sorcerer’s Stone” (2001).

As with the two previous films, screenwriter Steve Kloves adapted Rowling’s book, but for “Azkaban,” original director Chris Columbus stepped back into a producer role in favor of Alfonso Cuarón as director. At that point in his career, Cuarón had directed the family-friendly “A Little Princess” (1995) and the Oscar-nominated “Y Tu Mamá También” (2001); later he would win Oscars for editing and directing  “Gravity” (2013) and directing and cinematography for “Roma” (2018).

“Hedwig’s Theme,” named after Harry’s pet snowy owl, is one of the enduring motifs of the “Potter” films.

As The New York Times reported at the time, Cuarón’s vision of the Potterverse was “grainier and grimmer [than the two previous films]. It feels at once more dangerous, more thoroughly enchanted and more real. … This one lingers in the shadowy forests and damp meadows outside the school walls.”

Fortunately, the composer of the initial two films returned for the third, ensuring a musical consistency for the characters and the story. Williams had then received an astonishing 42 Oscar nominations, winning five (for such cinema classics as “Jaws,” “Star Wars” and “E.T., the Extra-Terrestrial”). He now has 51 nominations, an all-time Oscar record for music.

The original “Harry Potter” was Williams’ fourth film for director Chris Columbus, and as a fan of the Rowling books, he created an entire musical world for Harry and his friends in that initial outing, then built on them for the second film, “Harry Potter and the Chamber of Secrets” (2002). Surprisingly, his third score for the franchise uses only two themes from the earlier films: “Hedwig’s Theme,” music for Harry’s pet snowy owl and the sole motif that connects all eight of the films, and a reprise of the “Nimbus 2000” broomstick theme from “Sorcerer’s Stone.” The music is otherwise completely new — and, many observers have suggested, the best of Williams’ three “Potter” scores.

The composer began, months before shooting, by writing a “homecoming” song to welcome the students back to Hogwarts. As Williams told Variety at the time: “Alfonso sent me some literary material, including the witches’ scene from ‘Macbeth,’ which has ‘double double toil and trouble, fire burn and cauldron bubble.’ I thought that was perfect, so I sort of helped myself to Shakespeare,” he said with a laugh. “We added ‘something wicked this way comes’ [also from ‘Macbeth’] and sent it to Alfonso as a text, which he loved.” Sung by children’s chorus with a handful of instruments, it is heard at Hogwarts and then adapted for instrumental use here and there throughout the score.

A limited box set of John Williams’ three “Harry Potter” soundtracks was released this year.

Director Cuarón thought of the song as “a melodic, mischievous close cousin of ‘Hedwig’s Theme’,” and in his view, “it became the foundation stone for the rest of the score. Its medieval color became the musical identity of the wizarding world.” Indeed, the use of recorder, harpsichord and sackbut lent an early-music quality to much of the score. Williams said that approach was initially inspired by the ghostly appearances of Sir Cadogan racing through the halls of Hogwarts on his noble steed.

In addition to “Double Trouble,” the other major new theme heard throughout the “Azkaban” score is “A Window to the Past,” which Potter music expert Michael Matessino terms “a successor to the ‘family theme’ from the first two scores, a waltz associated with reminiscences about Harry’s parents.” The first 10 minutes of the film feature two delightful stand-alone pieces: “Aunt Marge’s Waltz,” which underscores a comedic moment when Harry takes revenge on an obnoxious relative, and “The Knight Bus,” a wild, big-band number with hints of Spike Jones for the suddenly appearing “emergency transport for the stranded witch or wizard.”

Other highlights include Williams’ soaring music for Harry’s flight aboard Buckbeak, a magical winged hippogriff; dark and menacing sounds, augmented by choir, for the nightmarish, soul-destroying Dementors, and the brief but colorful early-music pieces heard in the background in Hogsmeade Village and the Leaky Cauldron pub, including a charming holiday carol, “A Winter’s Spell.” The score was ultimately nominated for an Academy Award; its soundtrack album, for a Grammy.

As Williams said: “The effectiveness of these films is so connected to the imaginative use of music that it makes the work thrilling, constantly interesting and endlessly fascinating.” Added Cuarón, for notes in the recent box set of Williams’ “Harry Potter” music: “It’s a rich and complex score, and it holds even without the narrative in front of you like a great symphony. That’s the skill and art of John Williams.”

Jon Burlingame writes about film music for Variety and teaches film-music history at the University of Southern California.