Three decades after MGM ignored two invitations to show it at the Cannes Film Festival, the brilliant “Nothing Lasts Forever” will make its festival premiere at the TCM Classic Film Festival in Hollywood this weekend.

Zach Galligan of “Gremlins” fame will be on hand to introduce his film debut, a retro-futuristic fantasy that never got a US theatrical or video release and has scarcely been seen since then-owner MGM shelved it after a disastrous test screening — this despite a cast that includes Bill Murray and Dan Aykroyd, with other “Saturday Night Live” talents working behind the camera.

Zach Galligan in “Gremlins.”Warner Bros/Courtesy Everett Collection

Galligan, who still acts and teaches how to audition at New York University, told The Post about the film’s long, strange history, including failing his first audition for the lead role — as a concert pianist who is forced to work for the Port Authority (which has taken control of a post-apocalyptic New York City) but ends up finding romance on the moon.

As an 18-year-old student at Collegiate High School, Galligan was among a group of aspiring young New York-based actors going out for the same roles — including Andrew McCarthy, Kevin Bacon, Matthew Modine and Matthew Broderick. “Those were the big four I would run into all the time in auctions,” he recalls.

Galligan believes they all auditioned for his film, but he later heard that Matthew Modine was the choice of MGM and producer Lorne Michaels (of “SNL”) for the “Nothing Lasts Forever’’ lead. But Tom Schiller (who had directed shorts for “SNL’’) wanted Galligan instead. After open auditions where 1,500 candidates were looked at, Galligan was called back for a second audition, where Schiller asked him to mime playing a Chopin piece he’d never heard at the piano.

He landed the role on the spot. He was so excited at working with his comedy idols Murray and Aykroyd that he blew another audition that same day — for “Risky Business,” which catapulted a young actor from New Jersey whom Galligan regularly encountered to stardom. (Galligan and Tom Cruise both tried out for “Taps,” but only Cruise made the cut.)

“I would have felt bad about losing that in favor of a movie that virtually no one has seen for 33 years, except that I followed ‘Nothing Lasts Forever’ with ‘Gremlins,’ an iconic horror comedy that was produced by Steven Spielberg,” Galligan says.

Galligan says the death of John Belushi five weeks before “Nothing Lasts Forever” production began “cast a pall over the shooting of the movie. He was supposed to play the part that was taken by Shakespearean actor Paul Rogers. Everybody was heartbroken.”

The eclectic cast included veteran actor Sam Jaffe and comedienne Imogene Coca toward the end of their storied careers.

“When I met Sam, who was nearly 90, I was freaking out,” Galligan says. “My psychologist mother is a classic-film fan, so I had watched him in ‘Lost Horizon’ and ‘Gunga Din,’ and he wasn’t just another old geezer to me. He was a character-actor legend.”

Coca, best known for her work opposite Sid Caesar on the early TV show “Your Show of Shows,” was another favorite of Galligan’s mom. He said it was amazing watching her work with Murray, who plays a nasty guide on a tour bus to the moon in the surreal comedy.

Bill Murray in “Nothing Lasts Forever.”Handout

“She and Bill kept trying to out-improvise each other,’’ Galligan recalls. “I turned to Tom [Schiller] and said, ‘Trying to keep a straight face while doing a scene with these two is one of the hardest things I’ve ever had to do.’ ”

Among the other veteran performers in the cast was singer Eddie Fisher, who was cast as himself at the suggestion of his daughter, Schiller’s friend Carrie Fisher.

“He reluctantly agreed to a joke about his womanizing, but he was not happy about it,” Galligan says of the former Mr. Elizabeth Taylor. “He was no William Shatner when it came to mocking his persona. But Fisher also agreed to a promotional photo shoot for Italian Vogue where he’s singing with his arms spread, and Schiller and me are plugging our ears.”

The hardest thing, Schiller remembers, “was doing scenes with Murray, who was my absolute idol. From the moment I met him, he was determined to have me feel antagonistic toward him, because that’s how my character was supposed to react. But sometimes he’d forget the method stuff, and he’d creep back into mean mold. He’s a genius, and it was a privilege to work with him and Aykroyd, who’s a real mensch.”

The modestly budgeted $2 million production was shot entirely in New York, including Floyd Bennett Field in Brooklyn and the long-gone Danceteria. Interiors for Carnegie Hall — where Galligan gives concerts at the beginning and the end of the film — were filmed at the old Savoy Ballroom on West 44th Street, but there was also shooting outside the venerable concert hall. “The scene in front at the end of the movie was shot at 6 o’clock in the morning, but the one at the back entrance was shot with maybe 750 people watching and applauding every take,” Galligan says. “Pretty mind-blowing stuff for a high school student who was still living at home and had been driven to and from the set every day by Teamsters.”

MGM was bullish on the final film and planned a release for the fall of 1984 to cash in on “Gremlins” and Murray and Aykroyd’s “Ghostbusters,” both of which had been massive hits that summer. But a test screening in Seattle with fans “who got a film that couldn’t be less like those two blockbusters” went very badly, and a new executive regime at MGM wrote it off as a mistake by their predecessors. It didn’t help, says Galligan, that Schiller had included many clips from classic films that would have cost as much as a million dollars to license. So it didn’t even get a VHS release, and never was shown on American TV until TCM aired it in January as part of its Underground series.

I was outraged when I heard that MGM wouldn’t even let it be shown in Cannes.

- Zach Galligan

“I can’t really say they were wrong from a business point of view,” says Galligan. “But I was outraged when I heard that MGM wouldn’t even let it be shown in Cannes, where the critics would have loved it.”

“Nothing Lasts Forever” began building a cult following a decade ago when Murray insisted it be included in a retrospective of his career at the Brooklyn Academy of Music. Warner Bros., the current owner, allowed it to be shown there and at a subsequent sold-out screening at Lincoln Center, where Murray riffed for 90 minutes for a delighted audience. The super-hard-to-see film also created an Internet sensation when it briefly popped up illicitly on YouTube last summer.

Galligan has no regrets about his underseen film debut, which he calls “an amazing experience. I’m 18 years old and I had this scene where I’m being tested as an artist by the Port Authority, and there’s a totally nude female model. I’m thinking, ‘This is the gift that keeps on giving.’ Then I have what was supposed to be a PG-rated sex scene with the [Dutch] model Apollonia van Ravenstein. I’m under the covers in my tightie whities and, free spirit that she was, Apollonia strips down entirely. My jaws dropped. I asked Tom, ‘What am I going to do?’ He says, ‘Enjoy it,’ and I’m thinking this movie’s getting better and better by the second.”

Warner Bros. says they’re still working on the rights issues blocking a DVD release, but Galligan is optimistic. “Now that it’s finally showing in Hollywood, I’m starting to feel it’s inevitable this is going to see the light of day,” he says. “It’s a good little film that deserves to be seen.”

TCM is showing it again at 2 a.m. May 31, and “Nothing Lasts Forever” will also likely be available on the network’s Watch TCM app.