Of all the fans who have professed undying love for “The Princess Bride,” there’s one star Cary Elwes never expected to hear from: Pope John Paul II.

Elwes briefly met His Holiness at the Vatican in 1988, a year after the movie was released. After posing for a quick photo, the pontiff turned to the actor and asked if he was the one from “The Princess and the Bride.” (Infallible, my backside.)

Elwes was so startled, he could barely speak. “Yes,” he answered.

“Very good film. Very funny,” the pope said.

“I mean, what are the chances of that?” Elwes tells The Post. “‘Inconceivable’ was what went through my mind.”

Maybe the revelation wasn’t that shocking. “The Princess Bride” has earned millions of fans around the world — and not always those on the side of the angels.

Mobster John Gotti’s crew also enjoyed it. Many years ago, “The Princess Bride” director Rob Reiner was out at a restaurant in Little Italy when in walked Gotti and a crew of six henchmen.

Reiner finished his meal and walked outside, coming across one of the wiseguys standing in front of a limo.

“Hey!” the mobster yelled at Reiner. “You killed my father. Prepare to die!” Then he chuckled and said, “‘The Princess Bride.’ I love that movie.”

Don’t we all. The fairy tale is about a swashbuckler named Westley (Elwes) who has to rescue his true love, Buttercup (Robin Wright), before she is forced to marry the evil Prince Humperdinck (Chris Sarandon).

Along the way, Westley gets help from two outlaws, Inigo Montoya (Mandy Patinkin) and his oversized companion, Fezzik (Andre the Giant).

Now Elwes, 51, has written a memoir of his time on the set. “As You Wish” hits shelves Tuesday.

“We all get asked by the fans, ‘Was it as much fun making the film as it looked?’ I always say that it was more fun,” says Elwes. “I thought, rather than to try and explain it in a short meeting with fans, why not try and put it down on paper?”

“The Princess Bride” didn’t do particularly well during its initial theatrical release, earning a middling $30 million. The movie only acquired a rabid fanbase some years later when viewers began to discover it on VHS and DVD.

The script was by William Goldman, based on his 1973 novel, and the author had struggled for years to get a movie version off the ground.

Various incarnations had come and gone. One version was to star Arnold Schwarzenegger as the giant, Fezzik. Instead, the French-born wrestler Andre the Giant — who was 7 feet 4 and weighted 540 pounds — got the role.

Because Andre’s English wasn’t great, Reiner put the entire script on audio tape for him to memorize.

Elwes reveals Andre to be the most colorful character on set. He was a gentle giant, who called everyone “boss.” He was aware that people his size rarely lived long, so he tried to wring the most out of every day.

That philosophy included a big appetite for food and booze. Legend has it that Andre could down 100 beers in a single sitting, and his average daily consumption consisted of an entire case of beer, three bottles of wine and two bottles of brandy.

After the film wrapped, Elwes joined Andre for a night of drinking at P.J. Clarke’s on Third Avenue — one of the giant’s favorite Manhattan watering holes.

As Andre was downing his usual, a mix of hard spirits served in a beer pitcher, Elwes noticed a man sitting alone watching them.

Elwes and Andre eventually left Clarke’s and headed to a few other Manhattan bars. All the while, the man followed and continued to watch them.

When Elwes asked Andre if he noticed the stalker, the wrestler confided that the man was an undercover cop. After one of his previous nights of bar hopping, Andre had fallen over while waiting for a car, injuring a passerby.

Since then, Andre claimed, the NYPD assigned an officer to tail him whenever he went out drinking in New York.

“They said it was for my own safety,” Andre told Elwes.

Others needed to be protected from him, as well. In the scene when Westley is revived after being mostly dead, Andre interrupted one take with “the most monumental fart,” which was like an “earthquake.”

“That was a big one, wasn’t it?” Andre asked.

“The Princess Bride” shoot was beset by a few accidents, two of which nearly proved disastrous.

One day during a break in filming, Elwes took a joy ride on an ATV at Andre’s insistence. As he bounced over some rocks, his big toe got caught and snapped backwards, breaking it.

Fearing he’d be replaced, Elwes downplayed the injury and insisted on continuing to film, even though he could barely stand and walk.

Watch the scene shot that day in which Westley — disguised as the Dread Pirate Roberts — sits with Buttercup on a hillside and tells her, “Life is pain.” As he stands up, you can clearly see him favoring his right leg.

The other injury was suffered by Patinkin under even stranger circumstances.

After Westley is rendered “mostly dead” at the hands of the evil prince, Inigo and Fezzik carry him to Miracle Max, an elderly healer played by Billy Crystal, who based the schticky character on his grandmother and former Yankees manager Casey Stengel.

Reiner gave Crystal free rein to improvise, and many of the scene’s memorable lines were ad libbed, including the crack about true love being the greatest thing next to a good MLT — mutton, lettuce and tomato.

The cast and crew had trouble keeping their composure. Reiner had to leave the room after ruining several takes, and Elwes — who was supposed to lie motionless on a table, pretending to be mostly dead — had to be replaced by a dummy, because he couldn’t keep from cracking up.

Patinkin kept his laughter bottled up and actually bruised a rib holding it in.

The final mishap involved Elwes and the scene in which Christopher Guest, playing the prince’s sidekick Count Rugen, knocks Westley out with the butt of his sword.

During the first few takes, Guest faked hitting Elwes, and the stunt never looked convincing. So Elwes suggested Guest hit him for real — but lightly.

On the next take, Guest swung a bit too hard, connected with Elwes’ head and knocked him out for real. That take ended up in the movie.

Legend has it that Andre could down 100 beers in a single sitting.

Less violent means were involved in persuading Mark Knopfler of Dire Straits to compose the score.

The guitarist said he’d do it under one condition: that Reiner sneak the USS Coral Sea baseball cap worn by his character Marty DiBergi in the 1984 rock mockumentary “This Is Spinal Tap” into the movie.

You can spot it hanging in Fred Savage’s bedroom as Peter Falk, playing the youngster’s grandfather, reads him the story of “The Princess Bride.”

The scene that required the most preparation was the duel between Westley and Inigo, described in the screenplay as “The Greatest Swordfight in Modern Times.”

Goldman had spent months researching fencing and filled the script with references to particular styles and defenses.

Elwes and Patinkin trained for nearly three months, working with stunt coordinators on the choreography. The actors begin the scene fighting with their left hands, then, in a twist, switch to their right.

Mid-battle, Inigo smiles and tells Westley, “I know something you don’t know. I am not left-handed.”

“There’s something I ought to tell you,” Westley replies. “I’m not left-handed either.”

The gag required the actors to become ambidextrous with the sword — a feat that the stunt coordinators didn’t think was possible, so the production had doubles standing by, in case.

The scene was among the last to be filmed, giving Elwes and Patinkin more time to train. A couple weeks before the cameras were to set to roll on the duel, after hundreds of hours of work, the actors demonstrated the scene for Reiner.

After it was over, Reiner scratched his beard and asked, “That’s it?”

The stunt coordinators had originally demonstrated the scene to the director at half-speed, making it seem longer than it ended up being when Elwes and Patinkin performed it at full speed — just 1 minute and 23 seconds.

The actors and choreographers were sent back to the drawing board and lengthened the sequence to nearly 3 minutes by borrowing elements from other swashbuckling movies such as “The Mark of Zorro” and “The Sea Hawk.”

Reiner avoided another potential pitfall with an alternate ending penned by Goldman that was shot but (thankfully) never used.

The finale found Savage’s character in his modern-day bedroom leafing through “The Princess Bride” book when he hears a noise outside.

He looks out the window to find the fairy tale characters — Westley, Inigo, Buttercup and Fezzik — sitting on horses and “beckoning him to join” the next adventure.

Elwes isn’t quite sure why the film has endured for so long. In “As You Wish,” he offers that it’s because “it was made with a lot of heart.” It’s about as uncynical a film as you can find.

“In the film, [Goldman and Reiner] were able to explore that love of storytelling in a way they perhaps will never be able to again.”