None of this might have happened were it not for one unfortunate Spider-Man fan whose boiler broke down.

Back in 2006, comic book and toy dealer John Cimino bought a collection from a seller who needed money for a new hot-water heater. Within the assortment of pop-culture oddities for which Cimino paid $500 was a cheap, rayon-and-cotton Halloween costume from the 1960s featuring Spider-Man.

“I didn’t think twice about it,” Cimino tells The Post. He tossed it in his basement.

But Cimino would later give that costume a closer look, and what he discovered has led to one of the more puzzling mysteries in the superhero world, and might muddy the origin story of one of the world’s most well-known — and lucrative — characters.

Marvel Comics’ Spider-Man first appeared in 1962’s “Amazing Fantasy” No. 15. He was created by writer-editor Stan Lee and artist Steve Ditko. Lee has said that the hero was inspired by a 1930s pulp crime fighter called the Spider.

Ditko designed the costume to “fit in with the powers he had,” the artist wrote in a 1990 issue of Robin Snyder’s “History of the Comics.”

But could the illustrator have actually found inspiration in a child’s costume?

That Spidey suit Cimino bought was produced by Ben Cooper, Inc., a now-defunct Brooklyn company founded in 1937. The costumer originally created theatrical wardrobes but soon moved into kids’ Halloween outfits — many of them licensed, including a 1937 line based on Disney’s “Snow White and the Seven Dwarfs.”

After reading a book about mid-century collectibles, Cimino, 41, re-examined his Ben Cooper costume and quickly became obsessed with the company.

“I started digging deeper,” he says. “I dug and dug and dug.”

As he continued researching the company, he came across catalogs from the 1950s, and one particular image left him scratching his head.

There, in one 1954 circular, was an offering for a “Spider Man” costume that looked slightly different from the one he had just purchased. The get-up had a spider logo on the chest and a distinctive web pattern across the bodysuit and face mask.

In other words, it immediately called to mind Marvel’s Spider-Man, who wouldn’t be introduced for another eight years.

“I thought, hmm, that’s weird,” says Cimino, who runs Massachusetts’ Saturday Morning Collectibles, selling online and at shows.

The dealer, however, thought the costume was simply a prototype and was never produced. Until, that is, he got a call from a seller who once owned a five-and-dime store and had some leftover inventory in an old barn.

Stashed among the piles were a few old Ben Cooper Halloween costumes, including that mysterious Spider Man from 1954.

“I saw it, and I thought, Holy s–t! It does exist!” Cimino says. “I didn’t jump around, but I was s—ting my pants.”

Ben Cooper costumes were once ubiquitous. The company reportedly owned between 70 and 80 percent of the Halloween market in the ’60s. In 1963, Cooper moved some 2.5 million units.

“Ben Cooper was 10 miles from Marvel’s offices,” Cimino says. “Ben Cooper ruled Halloween in New York City, so Ditko had to have seen this costume. When he got the assignment for Spider-Man, maybe something came back when he was designing it. It’s so much like the Ben Cooper.”

Late last year, Cimino mailed photos of the yellow 1950s costume to Ditko, 87, who still works near Times Square but shuns publicity and hasn’t done a formal interview or taken a public photo in decades. The artist sent back a terse, handwritten reply.

“The burden of proof is on the person who makes the assertion, claim, charge,” Ditko wrote. “Some clippings, etc., are not rational proof of anything but some clippings, etc.”

Then again, the similarities may be down to another Marvel artist. Jack Kirby, who died in 1994, claimed a few times that he created Spider-Man, and a 1975 issue of FOOM!, a Marvel-produced fan magazine, states, “It was Jack Kirby who designed Spider-Man’s costume.”

After all, Stan Lee did originally tap Kirby to draw Spider-Man, and the artist reportedly created five pages before Lee changed his mind and gave the assignment to Ditko. (According to Ditko, Kirby’s version of Spider-Man looked nothing like the hero we know today — though everyone involved has a different recollection. Marvel declined comment through a representative.)

Ben Cooper’s records were destroyed in a 1989 fire, and the company was sold in 1992, but rumor has it that in the 1950s, Kirby worked briefly for the company. Could he have designed that 1950s Spider Man costume before repurposing it for Marvel a few years later?

Where the story gets even stranger is when Cimino went back to that original licensed Spider-Man costume he’d bought from the man who needed a new boiler. He realized the copyright on the packaging and costume said it was produced in 1963, a few months after Spider-Man’s first appearance. Turns out it was actually Marvel’s very first piece of licensed merchandise, hitting shelves a year earlier than anything previously known. Just three costumes are now known to exist, and Cimino has been offered $30,000 for his.

The licensed costume has a red mask — not yellow, as the 1954 Ben Cooper did — though both have the big spider eyes with black outlines. The licensed jumpsuit is partially yellow on the chest, with blue pants and sleeves.

So why would Ben Cooper, a company that was already producing a Spider Man costume, be interested in licensing Marvel’s Spider-Man long before the comic character achieved mainstream popularity?

“When Spider-Man hit the newsstands in 1962, I think Ben Cooper saw it and thought it looked like his costume,” Cimino says. “Then he went to [Marvel head] Martin Goodman, and I think they came to a deal where Cooper said, ‘Listen, this looks a bit like mine.’ I don’t think it was a big deal.”

As for Stan Lee, Cimino once met the Marvel honcho at an event and asked him about the mysterious licensing deal. Lee had no recollection of the costume.

“No one is going to talk about this, because there are billions of dollars at stake,” Cimino says. “You don’t know if the Ben Cooper heirs are going to come out of the woodwork and sue or something.”

If they do, expect to find them hanging from a lamppost, tangled in webbing.

The amazing origins of Spider-Man

1954: New York costume company Ben Cooper, Inc., sells outfit called “Spider Man.” Marvel Comics artist Jack Kirby is rumored to have worked briefly for the company, perhaps designing costumes.

Late 1950s: Ben Cooper alters its “Spider Man” costume design, swapping the bag-like mask for a yellow, plastic spider’s web. The new design is sold until 1962.

1962: Writer-editor Stan Lee assigns Kirby to produce Marvel’s new comic, “Spider-Man.” The artist draws a few pages, but Lee deems them not right and hires Steve Ditko instead. Ditko claims to design costume.

August 1962 (cover date): Spider-Man debuts in “Amazing Fantasy” No. 15.

March 1963 (cover date): The hero’s solo title, “The Amazing Spider-Man,” hits shelves.

October 1963: Ben Cooper strikes deal with Marvel — terms unknown — and begins selling a licensed Spider-Man costume, making it the comic company’s first piece of merchandise.