After Sony attempted to reboot its “Spider-Man” franchise with Andrew Garfield as the web slinger, the studio is ready to give it a third try, this time with Kevin Feige, the man who has produced 10 consecutive blockbusters for Marvel Studios.

A deal to free up Spider-Man to appear in the Marvel cinematic universe, starting in 2017, is a clear admission by Sony that its superhero strategy with one of the most popular comicbook heroes around simply isn’t working.

That’s especially true at a time when the studio is desperate for some major film franchises. Struggling with one of the comicbook industry’s most popular superheroes was starting to get embarrassing — especially when “Guardians of the Galaxy,” starring a cast of misfits unknown to most moviegoers, broke out as a bigger hit in 2014 than the last “Spider-Man” movie when it made $774 million. “The Amazing Spider Man 2” earned nearly $709 million worldwide.

“The Amazing Spider-Man 2” just wasn’t the billion-dollar hit that former Sony Pictures co-chair Amy Pascal had been looking for last year — and needed to be in order to keep full control over the character. That movie became the lowest grossing film of Sony’s five Spidey films to date, and forced the studio to instantly start rethinking its plans for the character, even giving up a piece of the franchise.

A month later, at Comic-Con, Sony started reacting — to the dismay of some Marvel brass.

A third “Spider-Man” was moved to 2018, in order for Sony to launch films around the superhero’s villains in “Sinister Six” in 2016, and a spinoff film around another Spidey foe, Venom. Ideas were also kicked around to introduce a female set of heroes in their own films; one project even was conceived around Peter Parker’s Aunt May.

That may have been the last straw for Feige, who has long wanted to figure out a way to work Spider-Man into his films that feature Avengers including Iron Man, Captain America, Thor, the Incredible Hulk, Hawkeye, Black Widow, Nick Fury, and eventually Ant-Man, Doctor Strange and Black Panther. In the Marvel comicbooks, Spider-Man plays a key part of that group.

Feige now gets his wish in one of the rare studio collaborations involving some of the biggest box office draws at the megaplex, while giving fans a character crossover they’ve long been clamoring for.

Through a new partnership with Sony, the president of Marvel Studios will be central in coming up with a new storyline to launch the character — most likely without Garfield in the lead — and find a way to incorporate him into future “Avengers” movies, perhaps even sooner than that, like “Captain America: Civil War,” given the character’s key role in pitting Iron Man and Captain American against each other.

The New York City in which Iron Man has his Stark Tower now also gets to be the same city in which Spider-Man swings around. There are no alternate universes anymore, just one big superhero-filled metropolis.

The deal comes at a time when Sony needs not only hits at the box office but major franchises. It’s why “Ghostbusters” is being revived, this time with a female cast, and why properties like “Uncharted,” based on Sony’s hit videogame franchise are finally getting a greenlight, and why the studio was even considering mashing up its “Men In Black” series with “21 Jump Street.”

“This is the right decision for the franchise, for our business, for Marvel, and for the fans,” said Sony chairman Michael Lynton.

And for Pascal, she gets to maintain oversight of her biggest film franchise — one she nurtured while running Sony Pictures, and one she loves as a comicbook fan, especially the “Spider-Man” series.

Marvel has been trying to loosen up Sony’s ties to Spider-Man since October 2014, as was revealed in email exchanges after the hack on Sony’s computers in December.

The resulting deal is the same that was proposed back then: Sony maintains “creative control, marketing and distribution,” while Marvel gets to produce new “Spider-Man” movies that pairs him up with its other superheroes controlled by Disney. While Sonys’ Pascal was unsure at the time in her email exchanges with Sony Pictures president Doug Belgrad, both wound up agreeing that the final impact at the box office would be too hard to pass up.

Any deal will have had to figure out how to compensate Avi Arad, the former Marvel chief who originally licensed the company’s top characters, including Spider-Man and the X-Men to studios like Sony and Fox for film adaptations. He has long been attached as a producer to the Spidey franchise and a Venom movie, but has recently been looking to loosen his grip as he spends more time focused on producing reboots of “Popeye” for Sony, getting the rights to Nintendo’s “Super Mario Bros.” and launching new franchises in Japan and China. He also tired of having to spend months in New York City, where the recent Spider-Man films were produced.

Sony has owned the feature rights to Spider-Man since 1999, when Marvel sold the comic book story for $7 million.

“Avi is 66 years old,” says one source close the producer. “Creativity drives him and he’s finding that creative vision in other places these days. He certainly doesn’t need the money.”

A number of producers had stepped up in recent months to get control of Spider-Man.

Those include former Warner Bros. exec Jeff Robinov, whose Studio 8 is based on the Sony lot and is backed by Chinese investors.

In November, he outlined a plan to reboot Spider-Man as an adult and to avoid retelling the now well-known origin story. His plan: to hand the franchise to a filmmaker like a Brad Bird, “Frozen’s” Chris Buck and Jennifer Lee, “Whiplash’s” Damien Chazelle, Joe Cornish (“Attack the Block”), “Guardians of the Galaxy’s James Gunn, “The Lego Movie’s” Phil Lord and Chris Miller, “Jurassic World’s” Colin Trevorrow, Edgar Wright or the “Harry Potter” franchise’s David Yates.

“To argue that there’s plenty of other superhero movies with levity in the marketplace, so why make more ‘Spider-Man’ movies, would be akin to saying there’s no room for James Bond films because of all the espionage films and franchises that have come out over the years,” Robinov wrote Pascal in an eight-page memo. “There will always be room for this beloved, iconic hero.”

“Captain America: The Winter Soldier” helmers Anthony and Joe Russo also had emailed Pascal of their desire to retool the Spidey series, according to various sources.

Disney already has controlled Spider-Man’s merchandise rights since 2011, when it bought out Sony’s licensing arrangement involving the character.

The deal at the time was meant to “simplify our relationship,” according to Walt Disney chief Bob Iger. “This transaction will allow us to control and fully benefit from all Spider-Man merchandising activity, while Sony will continue to produce and distribute ‘Spider-Man’ films. We expect it will drive attractive returns for Disney,” starting with “The Amazing Spider-Man,” in 2012.

That’s been an understatement. But Disney and Marvel clearly saw better movies as a way to generate even more money from product sales.

And now Feige will get the chance to prove it. After launching “Gaurdians of the Galaxy” as a major new franchise around characters, including a talking tree and gun-toting raccoon, that few moviegoers were familiar with last August, it’s clear that it will be tough for Marvel fans to wait to see what he does with Marvel’s most popular character.