As his megahit CBS sitcom “The Big Bang Theory” prepared to end its run, Chuck Lorre came up with a wild pitch for a spinoff. Not “Young Sheldon” — that prequel was already, on the air and doing gangbusters. No, Lorre had something even more fantastical in mind.

“I had a strange idea that there was a portal in the back of the comic book store that led to other dimensions, and that Stuart, played by Kevin Sussman, could lead us on an action adventure-comedy-science-fiction mashup,” he tells Variety.

But here’s the rub: “No one really liked the idea,” he admits. Hard to believe, especially coming right off one of the most successful TV comedies of all time, that someone like Lorre would face a network and studio rejection. But Lorre says those programming execs were looking for something a bit more conventional and a little less — well, whatever it was that Lorre had conjured.

“Everybody wanted a spinoff of ‘The Big Bang Theory,’” he says. “They wanted it with the principal players, which is understandable. I didn’t want to do a spinoff with the principal players. I wanted to do something entirely different, and challenging — something I’d never done before. Which is certainly what we have now.”

What they have now is HBO Max’s 10-episode “Stuart Fails to Save the Universe,” which premieres July 23 on the platform. After the initial pitch was a pass, Lorre temporarily shelved the idea, keeping busy with series like “The Kominsky Method” and “Bookie.” But he never gave up on “Stuart,” bringing in “Big Bang” co-creator Bill Prady and sci-fi-comic expert Zak Penn (“The Avengers,” “The Incredible Hulk”) to hone the concept and write the script.

“Chuck recruited me sometime during the pandemic,” Penn says. “The thing that grabbed me was from the very beginning, he said, ‘I want to do a spinoff that’s not like any other spinoff you’ve seen,’ where the tone and the genre shift. He wanted to do something that was in the sci-fi fantasy realm, so that’s up my alley. It was an easy yes.”

As for Prady, “my favorite episodes of ‘Star Trek’ were always the comedic episodes, and so the idea of playing in comedy science fiction was like, ‘Let’s figure this out.’”

Meanwhile, just in case it might actually happen, Lorre had kept Sussman on standby. “He wanted to pitch me the idea of a spinoff about Stuart,” Sussman says, “which is weird because, does that mean he was imagining I might say ‘no’?”

Years later, Lorre, Penn and Prady finally came up with a spinoff pitch that secured a greenlight from Warner Bros. TV and HBO Max. “That surprised the heck out of me,” says Lorre.

In “The Big Bang Theory,” Sussman’s comic book store owner, Stuart Bloom, was a minor player. But he’s front and center in “Stuart Fails to Save the Universe,” as he and his friends bounce through the multiverse after a quantum interference device created by “Big Bang”’s Leonard, Sheldon and Howard (referenced, but not seen) malfunctions. In this new alt-reality, Stuart and his comic book pals contend with alternate, uniquely dangerous versions of the shop and its Pasadena environs.

And that doesn’t begin to describe how far-out the show gets. In one episode, a familiar face is turned into a 60-foot witch. In another, one of the stars turns into a magical wizard. Each episode is its own story and setting — and as the title hints, Stuart never manages to make things right.

“It’s so outside of the box, and it’s so not like the original show,” says Sussman. “It’s a huge risk in terms of doing something completely different, but on the other side, it is still Chuck Lorre, and it is based on beloved IP. I love that he took such a big swing, because I don’t want to have to be compared to the original multi-cam.”

Besides Sussman, leading the show are fellow “Big Bang” alums Lauren Lapkus (as Stuart’s love interest, Denise), Brian Posehn (Bert) and John Ross Bowie (Kripke). But plenty of other “Big Bang” players make cameos as multiverse versions of their characters — and even recurring faces from the original series, like Wil Wheaton (once again as himself), show up. Then there’s a new character, Gary (Tommy Walker), a potential rival for Denise’s affections in the show’s various worlds.

It’s a long way from the multi-camera, studio-audience comforts of “The Big Bang Theory.” For one thing, that show never featured any gunshots, explosions — or a high, gruesome body count, for that matter. But “Stuart Fails to Save the Universe” sure does. At one point during production, Sussman and Lapkus were latched onto cables and hoisted to the ceiling of a Warner Bros. soundstage. And then they were dropped. Beneath them, huge industrial fans were blowing to make it look like they were plummeting through a void.

“In the script, we’re supposed to be screaming,” Sussman says. “But Lauren and I both thought the cable broke and that we were just lunging toward a giant fan. Rather than screaming, it was almost like we couldn’t get any air, and we were struggling to squish out some sound.”

With its special effects, travel through space and time and bloody deaths along the way, “Stuart” is living up to Lorre’s desire to make it one of the most unusual TV spinoffs of all time.

For one thing, the VFX costs on “Stuart” were unlike anything Lorre had previously spent on any of his other shows. But the producers figured out a way to make the series work, and they even brought the show in under budget. (It probably helps that “Stuart” doesn’t come with the pricey salaries for talent that “Big Bang” eventually faced in success.)

The producers also credit shooting in Los Angeles, thanks to the state of California tax credit. Filming locally allowed them to hire a top-tier crew who could pull off the show’s stunts and effects on a dime, they said.

“It’s much easier when you shoot in L.A. to get the cream of the crop in every department, because creating a good effects-driven show is not just about the visual effects,” Penn says. “It’s about the production design. It’s about the cinematography. I also think they gave us a good enough budget to go out and create real special effects.”

Prady notes that the science is legit on “Stuart” — or as legit as it can be for a sci-fi comedy about a quantum interference device that malfunctions and causes our characters to fall through the multiverse. ”That moment happened in the prime universe, but there’s no episode that takes place of these 10 in the prime universe. So is it canon? It’s multiverse canon!” he says. Lorre retorts with a joke: “Don’t poke at it too much!”

There are “Big Bang” Easter eggs all over “Stuart,” which Lorre says makes sense: “We’ve long determined that this is the kind of show that the characters on ‘The Big Bang Theory’ would have not only watched, they would have argued about,” he says. At the same time, Sussman doesn’t think you need to have been a “Big Bang” fan before watching “Stuart.” “I feel like they did a really good job of orchestrating these three four characters,” he says.

One element familiar to Lorre sitcom fans is back: His famed vanity cards, where Lorre takes the opportunity to converse with his viewers. As he makes clear at the end of Episode 2: “Throughout the making of ‘SFTSTY,’ my mantra was ‘Go crazy or go home.’ As you can see, I didn’t go home.”