Comic book geeks were surprised in May when it was announced that Zack Snyder would (for family reasons) step away from finishing his work directing DC’s “Justice League,” and Joss Whedon — who directed Marvel’s two “Avengers” movies — was taking over the superhero mash-up.

After seeing the final product, intermittently exciting and sometimes overstuffed, Whedon’s selection makes sense — because Snyder was following the Whedon playbook all along.

Like Whedon’s first “Avengers” movie, Snyder’s “Justice League” falls into three parts: the assembling of the team, the team’s faltering early battles and internal squabbling, and the slam-bang finish in which — spoiler alert — good triumphs over evil.

Part 1 shows the two surviving characters who have had their own movies, billionaire Bruce Wayne aka Batman (Ben Affleck) and Amazon-among-humans Diana Prince, alias Wonder Woman (Gal Gadot), recognizing a grave threat to humankind. That threat is Steppenwolf, a giant horn-helmeted humanoid monster (voiced by Ciaran Hinds) with an army of insect-winged demons.

Diana gives Bruce the backstory, that Steppenwolf is seeking three “motherboxes,” otherworldly cubes that when combined would release enough energy to rearrange the planet. Bruce and Diana start recruiting superheroes to join the battle. Bruce meets the ocean-savvy Arthur Curry (Jason Momoa), better known as Aquaman, and the superfast teen Barry Allen (Ezra Miller), who goes by The Flash. Diana seeks out the thought-to-be-dead Victor Stone (Ray Fisher), who’s now partly made of alien robotics and eventually will answer to the name Cyborg.

Snyder and screenwriter Chris Terrio (who shares screenwriting credit with Whedon after a massive rewrite) take up a lot of the movie’s first half introducing us to the three new characters. There’s also an early action set piece, of Wonder Woman taking down some terrorists in London, that feels tacked on by Warner Bros. executives who saw this summer’s “Wonder Woman” grosses.

Part 2 has the group battling Steppenwolf unsuccessfully, which puts the five superheroes at odds with one another. The arguments get heated when Bruce suggests a radical plan: Use the energy from one of the cubes to revive the deceased Superman (Henry Cavill).

It’s about here that Snyder’s touch seems to subside and Whedon takes the wheel. Whedon’s skill at combining heroic speechmaking with smartly snarky humor — a trait he honed writing “Buffy the Vampire Slayer” and “Firefly,” and that he perfected in the “Avengers” movies — gets a workout here, with Miller benefitting the most with his reading of Barry as a socially awkward speedster whose mouth is nearly as fast as his feet.

Whedon also cuts through a thicket of fan service, with brief appearances of favorite characters from the DC Extended Universe: reporter Lois Lane (Amy Adams), grieving Martha Kent (Diane Lane), trusty butler Alfred (Jeremy Irons) and the Amazonian queen, Hippolyta (Connie Nielsen).

There also are new faces to the current DC lineup: gruff Commissioner Gordon (J.K. Simmons), the Atlantis princess Mera (Amber Heard) and Barry’s imprisoned father (Billy Crudup). Giving everyone a moment without making the whole movie feel bloated is a trick Snyder and Whedon only pull off some of the time.

The core team is good, with Affleck, Momoa and the newcomer Fisher putting in solid efforts. But, as she did in “Batman v Superman,” Gadot’s portrayal of Wonder Woman — robust, athletic and kind-hearted — saves the day and makes “Justice League” a team worth following.

* * 1/2

Justice League

DC Comics’ biggest heroes, led by Wonder Woman and Batman, face an extinction-level threat in this uneven action drama.

Where • Theaters everywhere.

When • Opens Friday, Nov. 17.

Rating • PG-13 for sequences of sci-fi violence and action.

Running time • 121 minutes.