You know you've offended Joss Whedon when he stops talking in Whedonisms. Usually the writer-director is funny, wry, and acutely self-aware—just like the characters he creates for his shows and movies, from the cult TV series Buffy the Vampire Slayer to the new horror flick The Cabin in the Woods. He'll order a chardonnay at lunch and slouch sideways in a booth, riffing on geek tropes from Star Trek to Twilight Zone.

But suggest that his TV show Dollhouse was really just about a pretty girl in a dominatrix outfit getting beaten up every week and Whedon transfigures into Buffy's erudite, ever-so-slightly supercilious mentor, Giles—if you could imagine Giles in a hoodie. The words get longer, the references more arcane. He sits up and leans over his plate of scallops, elbows on the table. The professor has arrived, and class is in session.

Dollhouse aired for 25 episodes on Fox in 2009 and 2010. It was Whedon's fourth show, and it had all the elements that made Buffy so great—ass-kicking ingenue, crackling dialog, plenty of sci-fi weirdness, and enough subtext to choke a lit-theory major. It was also, as Whedon himself admits, potentially the most offensive television program of all time. The story—a secret organization mind-wipes attractive people, reprograms them, and pimps them out to clients—was like an icky Fantasy Island with gunfights and psychosis. Even diehards who'd stuck with Whedon since Buffy didn't get it. "Bless their hearts, the fans were all going, 'It's Joss. We trust him. Maybe we're missing how it's good,'" Whedon says. "It was very sweet."

Still, he's sure the audience was in some part wrong about Dollhouse. Just a few nights before this lunchtime exegesis, he happened to see a clip from the show and was struck anew by it. Wait a minute, he thought, this show is meaningful. It wasn't just a girl getting beaten up—it was what Whedon calls "the most pure feminist and empowering statement I'd ever made—somebody building themselves from nothing." He wanted to do a show that would deconstruct identity and relationships and socialization ... and celebrate human perversion.

Whedon's enthusiasm for Dollhouse's complex narrative and subtext is so infectious that it's easy to forget the show flopped. Completely. But none of the movies and TV shows he's created have been mainstream hits. Not Buffy. Not the sci-fi Western Firefly. Not Serenity, the movie based on it. The most successful, arguably, have been the ones over which Whedon had the most control, like Buffy or the independently produced and digitally distributed Dr. Horrible's Sing-Along Blog. He thrives on independence, and studio brass who want him to rein in his darker impulses just get in the way.

Yet just up the LA street from the restaurant we're in is Marvel Studios, where Whedon is directing The Avengers, this summer's mega-ultra-awesome crossover superhero blockbuster. It is not a project that welcomes independence. Produced by Marvel, distributed by Marvel's owner, Disney, and with a story line all but predetermined by Marvel, it is perhaps the absolute Bizarro-world opposite of independence. The Avengers unites the narratives of five interconnected movies from the past few years and is the ignition point for a decade of potential sequels and new superhero pictures. With the turbines of the Disney-Marvel machine spinning up, why would the company let this commercially unproven director—no matter how smart he is—helm the ship?

Then again, tent-pole blockbusters are a pain in the ass to oversee. Whedon has a fan base that rivals Star Trek's in its ferocity, and he's doing just fine producing smaller movies. So maybe the bigger question is, why would this cult-favorite writer-director ever put up with The Avengers?

Buffy the Vampire Slayer began as a failure. Whedon, then a young writer toiling in the sitcom fields, wrote it as a movie script that pivoted on a central twist: A vicious monster follows a beautiful teenage girl into a dark alley, and only the girl walks back out. Whedon wanted to make the ingenue into an action hero, to literally empower a young woman. But the 1992 film, directed by Fran Rubel Kuzui, turned into a slapstick farce. It's not without charm, but big-screen Buffy seems petulant, and the jeopardy feels false. Too much flounce, not enough kickboxing.

Whedon went on to success as a screenwriter and script doctor, working on Toy Story and Alien: Resurrection and doing uncredited work like a rewrite of Speed. But a few years later TV producers got interested in redoing Buffy as a half-hour kids' show, the kind of thing that could run after Power Rangers. Whedon got on board. He even remembers the first gag he came up with for the show: A group of vampires would be waiting to attack Buffy, and one of them would say, "Why don't we all attack her at once?" A second vamp would respond, "Tradition. It's an honor thing." That narrative self-awareness, the promise to zig when most action shows predictably zag, was typical—"Whedonesque," even. Seeing Whedon's enthusiasm and the richness of his ideas, the newly formed WB network bought the concept as an hour-long drama and put Whedon in charge.

The series, which ran from 1997 to 2003, creates a metaphorical universe that renders the awfulness of adolescence through the conventions of horror and sci-fi. High school is hell—literally. Be ignored by your peers and turn invisible. Sneak out to a frat party and get molested by a giant white snake demon in the basement. Lose your virginity and your boyfriend becomes an evil monster. Sometimes you can communicate only through music; sometimes (because of magic) you can't communicate at all.

Courtesy Marvel Studios

Buffy and her friends at Sunnydale High went through all the same traumas as the kids on Freaks and Geeks and My So-Called Life. They wanted to have sex, and then they did, and it was weird. They couldn't pass chemistry. Popular kids made fun of them. But somehow, when all that common drama happened against the backdrop of apocalyptic villainy and portals to other dimensions, it became—to a certain subset of pop-culture consumers—not less believable but more relatable. Whedon had found his narrative sweet spot: making stories about what his fans felt but couldn't articulate.

How does he do it? "There's a lot of pacing and brow-furrowing, and then the ridiculous genius machine in his head will spit out an episode almost fully formed," says Jane Espenson, who has written for all of Whedon's TV shows. The vampire and werewolf stuff may have been cheesy, but the stories never were. Whedon told his writers to avoid "moves"—stuff that happens only for the sake of advancing the plot or for a cool action sequence.

"He's so good at surprising you in ways that feel totally authentic," says Marti Noxon, who wrote for Buffy and went on to work on Mad Men and write Fright Night. And, of course, he put in all the Whedonisms. Characters shorten words—situation becomes sitch—and clichés get flipped into asides like "Gosh, does the fun ever start?" The sparkly, shiny dialog he put into the mouths of his characters sounded like something he'd picked up hanging around high schools at lunch, but it was all his own invention. No wonder the show found a ready audience of cultural-studies academics, who jumped to unpack its many layers. (The exegetical cottage industry dubbed Buffy studies has given rise to articles like "Fans With a Lot at Stake: Serious Play and Mimetic Excess in Buffy the Vampire Slayer.")

Buffy's cult status defined the WB as a network of hot young people doing improbable things, a tradition that lives on in its offspring, the CW. But the show's magic proved difficult to replicate in Whedon's follow-up projects. Angel, a spinoff about Buffy's ex-boyfriend, ran for five years and had a few wonderfully weird episodes, but it never matched Buffy's cultural impact. Firefly attracted a similarly small (albeit way more vocal) fan base on the Fox network.

It began to seem as though Whedon's intellectual aspirations—the result of a film-major/unofficial-gender-studies-minor education at Wesleyan in the paradigm-subverting days of the postmodern mid-'80s—were getting in the way of success. As a student of film professor Jeanine Basinger, whose many successful ex-students include A Beautiful Mind writer Akiva Goldsman and Transformers inflictor Michael Bay, Whedon had learned to read films closely, to watch movie after movie until 3 am, finding not 10 things to say about the title number in Singin' in the Rain but 1,000. But now his command of subtext was starting to feel more like—well, like text. That Whedonesque self-awareness was verging on parody.

The cadre of folks he worked with regularly—actors, writers, producers—stayed loyal. But Whedon's audience remained stubbornly small. He fought with Fox network executives, then talked about the fights to the press. (Note to aspiring television writers: This is maybe not the best way to persuade a network to back your new show.) He tried to develop other Buffy spinoffs, but none took. His pitch for a Batman reboot was rebuffed in favor of what became Christopher Nolan's Batman Begins. His script for a Wonder Woman movie got trapped in development hell. (Dr. Horrible's Sing-Along Blog, made during a writers' strike, proved that people would buy single-shot entertainment online, but it was a sad musical comedy about a supervillain.) Financial problems at MGM were delaying the release of The Cabin in the Woods, which he'd written and produced back in 2009. On the web and at pop-culture nexus Comic-Con, where Whedon appeared on panels and walked the floor every year, he was a god. But in Hollywood? Not so much.

As they say in comic books: Meanwhile! Something strange was going on with movies about superheroes. They were getting good. And they were using tools from the same hardware store where Whedon shopped. Bryan Singer's X-Men pictures applied the conventions of the genre to shed light on how it feels to be an outcast. The first two Spider-Man movies played up the hapless geekiness of alter ego Peter Parker and the daydream fulfillment of being a wisecracking superathlete.

Not incidentally, these were all characters from comics published by Marvel. The characters from competing comics company DC—Superman, Batman, Wonder Woman, and the rest of the Superfriends—were lying fallow, even though the corporation that owns DC also owns Warner Bros. Pictures. Marvel, on the other hand, was doing so well with its A-list characters that in 2005 the company took the bold step of financing its own theatrical releases. It would translate its characters its own way.

Spider-Man had been indentured to Sony, and the X-Men and Fantastic Four were already at Fox, but the remaining roster of potential movie heroes was still plenty deep. First up: Iron Man, an alcoholic gazillionaire playboy who builds his own rocket-powered exoskeleton. Then there's the Hulk, a brilliant scientist who turns into a massively strong, uncontrollable green monster. Oh, and Captain America—a supersoldier from World War II brought into the present—and Thor, a hammer-wielding Norse god with superpowers and family drama that makes the real housewives of Atlanta look like the Osmonds. Unlike the gleaming, godlike DC heroes, Marvel characters are more likely to regard their powers as a curse than a blessing; great power has a pesky tendency to come with great responsibility. And that makes for pretty good movie plots.

All those characters had something else in common: They were the core of a comic book team that began in 1963 called the Avengers, Marvel's answer to DC's Justice League of America. Comics fans love team-ups—more heroes per page for the same cover price is a good value. And the Marvel Comics universe has always been tightly integrated; the cataclysmic devastation of Manhattan in The Spectacular Spider-Man could cross over into that month's Fantastic Four. But the idea that Spider-Man movies could happen in the same universe as X-Men movies? Save that kind of talk for the comics shop, kid. "On almost every movie," says Kevin Feige, head of Marvel Studios and a veteran producer of films based on Marvel comics, "the writer or director would go, 'Hey, could we add this character?' And someone in the legal department would say, 'No, we can't do that.'"

With Iron Man, though, Marvel itself was running the show—and suddenly the answer was, "Hell yes." Samuel L. Jackson's agents had called Feige to ask about a part in Iron Man—Jackson was, after all, the model for the revamped comics character Nick Fury, head of the security agency S.H.I.E.L.D. So Feige asked director Jon Favreau to add a scene with Jackson as Fury, welcoming Iron Man's alter ego to a larger world of superheroes. "He was not only telling Tony Stark about the Avengers," Feige says. "He was telling the audience."

The Whedon Way

It's not that Joss Whedon is repetitive. He just has a happy place, a set of themes and narrative motifs that have come to define his work. Here's a look at what to expect from any Whedon project—including The Avengers. Oh, and spoiler alert!—A.R.

Girl with superpowers Buffy. River Tam in Serenity. Echo from Dollhouse. Whedon loves to populate his work with ass-kicking ingenues, and Black Widow in The Avengers is no exception.

Great (dead) secondary characters Who were the kindest, funniest, most emotionally available characters in Serenity? Spaceship pilot Wash and preacher Shepherd Book. Who was dead by the end? You got it.

Snappy dialog Even some of the regulars in Whedon's crew of recurring actors can't quite handle his rapid-fire Whedonisms. For the raw feed, check out his comic book work, especially Astonishing X-Men.

Musical numbers Whedon taught himself to play piano before writing the songs in Buffy's musical episode. Angel had a recurring music-be-the-food-of-love riff too, and Dr. Horrible is a straight-up musical. None of the Avengers trailers show the Hulk crooning, but you never know.

Deep nerd-outs Whedon is a fount of fan service. His ensembles are precooked for fanfic potential—hell, he's even written comic books that take place in his shows' universes after they're canceled.

Angsty bad guys Not that you'd necessarily root for demon gods and megalomaniacal vampires, but when Whedon writes them you at least get where they're coming from.

Totally self-aware self-awareness Not only are Whedon's characters preternaturally aware of their own strengths and weaknesses, they're good at articulating them ... and they know they're good at it. "It's a flaw in my work that is enough of a virtue that I let it slide," Whedon says. "I make people ridiculously self-aware because I hate deception."

Photo: Everett

If Iron Man had flopped, the cameo would have been a throwaway joke. But the movie made $318 million in the US. And Disney's acquisition of Marvel at the end of 2009 was an all-in bet. Disney needed a hook into the audience of boys (a problem that's only grown more acute with the failure of March's John Carter).

Princesses weren't doing it; superheroes would. Lots of superheroes. Marvel started cranking out a new crop of movies, each featuring a different character, and fans began to realize that they hinted at a wider crossover potential. Stark had Captain America's shield in his house. The bad guy in The Incredible Hulk got injected with a version of the supersoldier serum that created Captain America. It wasn't that hard; Marvel was there to help the writers with a whole basket of Easter eggs: paramilitary agencies, Nazi scientists, magic cubes, secret formulas, and so on. The moviemakers started watching one another's rough cuts and consulting with a "creative committee" of Marvel Comics writers. "In the first Iron Man, the Easter eggs were simply inside jokes for the Marvel faithful," Favreau says. "By the time the second one rolled around, part of the agenda was to build toward The Avengers."

In its movies, Marvel had hit upon a secret formula of its own. Audiences learned to stay through the end of the closing credits, because a guest star would show up and say something portentous. Something wicked awesome this way comes.

But despite Feige's enthusiasm for The Avengers, the movie had problems. By February 2010 Feige had a script but no director. "We needed somebody who wasn't going to reinvent the wheel, because the die was cast and the cast was cast," Feige says. "And yet we wanted somebody with a unique voice, because this had to feel like a part one, not Iron Man 3 or Thor 2." (Those come out next year.) The Avengers would have to give rise to it own sequels and spinoff properties.

Worse, the movie was feeling awfully crowded. "The Avengers has so many characters, and the only reason for them to team up is some world-shattering threat, which equals spectacle," Feige says. "How can we navigate all those characters and not have them get lost in the action?" In other words, whoever directed it would need to be able to handle the storytelling and characterization issues that came with an ensemble. And while it wasn't a requirement, it'd be nice to have someone with geek cred—someone who knew their way around comic books.

Then Whedon's agent called to ask whether Feige would meet the director about working on The Avengers. Feige was already a fan. He had read one of Whedon's original (good) scripts for Alien: Resurrection, and in 2001 he had brought in Whedon to pitch himself as director for Iron Man. Plus, Whedon had done an uncredited rewrite on Captain America. All his shows had been ensemble pieces, and his best-known work had been in genre, giving him a thick coating of credibility. Whedon had even spent nearly four years writing a brilliant and much-loved X-Men comic book series. (His go-to move, the superpowered ingenue, was inspired by the X-Men character Kitty Pryde, a plucky young girl who can walk through walls.)

On the other hand, Whedon had directed only one movie—Serenity, a sequel to Firefly—which flopped. And his work was all just so ... intellectual. Feige was going to trust this guy with the tent-pole he'd been working toward for half a decade?

Well, yes. The project appeared bombproof enough that Marvel could take a risk with someone who had done smaller fare so well. "It might not be like this forever, but right now, in this genre, with these characters, the audience will at least come opening weekend," Feige says. "That liberates you to bring them to life with the most able—as opposed to just the most bankable—filmmaker." The strategy has worked before. Nolan was an art-house director before Batman Begins. X-Men's Bryan Singer and Spider-Man's Sam Raimi were quirky and small-scale before their comic book epics. (Plus, until they have a big hit, these kinds of guys command relatively small paychecks, and Marvel Studios has a reputation for cheapskatery on talent.) Going with Whedon seemed like the perfect solution.

Whedon had always wanted to direct a big summer superhero movie. But his unsuccessful runs at Batman and Wonder Woman bummed him out. "I had just come off of Dollhouse, which was rough, and I was determined to do my own thing," he says. Dr. Horrible had taught Whedon that he could just go make his own stuff—"with the caveat that should the perfect job be dropped in my lap, I might consider it."

So in March 2010 he went to the meeting with Feige intending simply to give his take on the script. What Whedon heard himself saying about it surprised even him. "I don't think you have anything," he said. "You need to pretend this draft never happened." He agreed to write a five-page story memo to tell the studio what he'd do with the movie. "In the process of writing it, I got that bug," Whedon says. "I realized, oh, yeah, this would be so much fun." Whedon pauses and adopts a mock-wistful look. "I was so young. So young."

He already cared about the characters—the comic book writer Jim Starlin's cosmic Avengers stories hooked him in the 1970s. But his key to cracking the screenplay was The Dirty Dozen, which reveled in the pleasure of assembling an ill-matched team. "The Avengers don't belong together," Whedon says. "Each belongs alone. But the more they're alone, the less useful they are."

Marvel went for his angle—with some restrictions. Whedon would have just 92 days to shoot, and the postproduction schedule was going to be brutally tight. The company told him the villain had to be the evil god Loki, from Thor. Execs said the movie had to have a big fight among the Avengers. They wanted a set piece in the middle that tore the team apart somehow. And there had to be an epic final battle. "I was like, great, you just gave me your three acts," Whedon says. "Now all I have to do is justify getting to those places and beyond them." He was in.

In a dark room at Marvel Studios, Whedon sinks into a sagging couch in front of a screen that takes up an entire wall, watching tiny scraps of his movie. Behind him, members of the visual effects team click away on MacBooks, waiting for Whedon to comment. The sequences come fast, each just a few seconds long, but in a way they're not fast enough. "It comes out May 4," Whedon says. "They'll pry it from our fingers. If I can just ride through these couple more months, then we should be OK."

Joss Whedon: Superhero

"I know it isn't effortless to write the way he writes, I know it takes a lot of work and a lot of choices are being made, but to read it is a pleasure. Not only is Joss good at ensemble, but he's very good at female characters, and Scarlett Johansson was given a big juicy steak to eat, and she killed it. I can't imagine ever seeing a better experience of the Hulk. And the meeting of Joss Whedon's words and Robert Downey Jr.'s lips is made in heaven. I watched and was like, 'Phew!'" –Brian Michael Bendis, writer, New Avengers, Powers

"If you're running a footrace against someone and a person gets across the line just ahead of you, you might get jealous. But if they're like 600 yards ahead, you can't get jealous. I was so in awe of what Joss could do that all I could do was marvel. Nobody's jealous of Superman. You just gape." –Jane Espenson, writer (Buffy the Vampire Slayer, Angel, Firefly)

"That guy is so smart.... One of his gifts is that for such an incredibly intelligent person he never makes you feel stupid. Unless it's funny."

–Nathan Fillion, actor (Serenity, Castle)

"I would say 90 percent of the time Joss really broke all our stories and drove that process. We'd sit in the room for hours and say, 'Maybe this is good.' And he'd come in the room for 10 minutes and say something that was 90 percent better. And we'd all want to kill ourselves." –Marti Noxon, writer (Buffy the Vampire Slayer, Fright Night)

"Joss' screenplay for The Avengers is one of the greatest pieces of screenwriting I have ever read. This film could have been such a tangle. He was trusted with the responsibility of combining the various tones and colors of different characters, many of whom have lead their own films, and trying to make a cohesive narrative that is thrilling, action-packed and entertaining and spectacular. And it was. I couldn't believe the story held together the way it did." –Tom Hiddleston, actor (Thor, The Avengers)

It doesn't help that Whedon is editing another movie at the same time. Between principal photography and postproduction on The Avengers, instead of going to Venice with his wife as they'd planned, Whedon shot his own adaptation of Shakespeare's Much Ado About Nothing. In 12 days. At his house. He and his assistant are editing it in Whedon's office at Marvel.

But the stress doesn't show. You can see why people love to work for him. He's insightful, and the Whedonisms fly. When the 3-D stops working for a second, he says, "The Ds are not three." Later, watching a shot of a futuristic airplane approaching the Helicarrier—S.H.I.E.L.D.'s massive flying headquarters—Whedon doesn't like how the sun shines through the jet's windows. "If it is a giant money problem," he says, "watch me stop caring with the alacrity of a true hack."

Then the screen flickers to black. "Sorry, Joss," says a young woman from the back of the room. "Technical difficulty."

Whedon stands up from his couch, turns around, extends his right arm, and says—in a pretty decent Darth Vader voice actually—"You have failed me for the last time!"

If only it were always this much fun. Marvel actually bounced Whedon's first drafts of the script. At one point it looked like the company might not use the Black Widow, played by Scarlett Johansson; Whedon told Marvel that without her the Helicarrier was going to feel like a gay cruise. Computer-generating the Hulk meant Whedon had to finish and edit every Hulk sequence a month before he finished shooting everything else. "So I'm writing, I'm editing, I'm shooting. I can't sleep. I'm like, great, it's just like running a TV show," Whedon says. Favreau gave him a piece of advice: "The machine will not let you fail. Just worry about being an artist and saying what you want to say."

Making a blockbuster, Favreau later explains, is easier in some ways than doing a small picture. On an indie film, the director has little support; the blockbuster has a team working on it. "On a movie like Iron Man, they're looking at suit design, how he flies, how he fights," he says. "If you want to do comedy and be left alone, don't do a comedy. Sneak it into an action movie."

But Whedon has never had much luck with machines. "The problem with the machine is that it will generify. It will suck the film out of the movie," he says. "Nobody does it on purpose, but without somebody telling them exactly what you need, they're going to give you something that would work for anything." Case in point: While working on a scene where Iron Man's armor shorts out, one of the previsualization guys said, "He should have a line here, something like, 'I'm getting too old for this shit.'" Whedon stopped short. "OK, we're going into a time machine," he said. "Three minutes earlier, you did not just tell me where a line goes. And it was not 'I'm getting too old for this shit.' That never happened. Let's move on."

Whedon's first edit of the movie clocked in at three hours. That's not unusual; first drafts are always long. What's unusual is what Whedon decided to cut. "I care about these people, about the fact that they're isolated," he says. "But I'm also telling Marvel's story. Much Ado allowed me to realize that taking away some of the Joss is going to make this a better Avengers movie."

The darker aspects of the dysfunctional team dynamic: out. A quiet scene with Captain America trying to absorb the craziness of modern-day New York: out. And so on. (The rapid-fire dialog and quips are still there, and an ingenue still does some day-saving.) "You don't have to say what you're trying to say. You can just do it, and then people will feel it," Whedon says. "The more I hone this and just focus on the Avengers as they relate to one another, the better it works. That's painful, but it's a reality."

The machine will make sure that The Avengers comes out on time and has cool explosions and fights. The Ds will be three. And maybe the truth about Whedon's work is that the more self-conscious it is, the narrower its audience. The Avengers wouldn't work as a self-aware, postmodern deconstruction of superhero team gender dynamics. Hulk gotta smash.

Whedon has plenty more personal projects on the way, if that's your bag. The Cabin in the Woods debuted at South by Southwest in March and opens wide in April, beating The Avengers to theaters. It's as crisp and surprising as all his writing is, and Whedon fans will be ecstatic—it's a horror movie about an audience watching people making horror movies about horror movies, packed with more male gaze than a Madonna video. He'll release Much Ado, of course, and he's working with comic book writer Warren Ellis on a web series called Wastelanders, which Whedon describes as "a hate letter to the human race wrapped in a love story."

So maybe The Avengers is the one where Whedon just makes the damn movie. It doesn't need to comment on anything. Except ... he yam what he yam. There's always a twist. Watching Black Hawk Down made Whedon realize that after waiting all his life to make a superhero movie, he didn't want to make one anymore. He wanted to make a war movie. "It can't just be 'fight until we reach the 1:50 mark and then go home,'" he says. "You gotta think they might fail." And if you're still wondering why Whedon would take on The Avengers, the idea of an against-all-odds battle with the highest possible stakes starts to sound like, well, a metaphor.

In fact, one of Whedon's favorite scenes in his movie happens during a lull in battle. It's a quiet moment between an exhausted Captain America and a less-exhausted Thor, neither admitting it, both saying with their faces that they might not be getting out of this one alive, but still heading back into the fight. Sounds pretty cool, right? Come on—it's Joss. You have to trust him.

Senior editor Adam Rogers (adam_rogers@wired.com) wrote about a fungus that eats whiskey fumes in issue 19.06.