In early 1994, NBC was desperate to secure the services of an actress for its new sitcom, then called “Friends Like Us.” The actress was a 25-year old named Jennifer Aniston, whose biggest role to date had been on the flop TV spin-off “Ferris Bueller,” but NBC was certain she was the next big thing.

There was only one problem: Aniston was under contract with CBS, starring in an upcoming show called “Muddling Through.”

NBC negotiated with CBS for her services and reached a deal. Aniston could shoot the first six episodes of “Friends Like Us,” but if “Muddling Through” got picked up on CBS, Aniston was gone.

And so NBC set out to sink its rival’s series.

The network’s head of schedule, Preston Beckman, devised an ingenious bit of sabotage. NBC had been sitting on several unaired TV adaptations of Danielle Steel romance novels.

Wouldn’t it be a pity, Beckman mused, if he were to air those adaptations on the Saturday nights that “Muddling Through” — whose audience was also heavily female — was playing over on CBS?

The Steel movies might suffer a bit of a ratings hit airing on Saturday nights, but it would be worth it to secure Aniston.

And that’s what NBC did, ultimately torpedoing “Muddling Through” and ensuring that Aniston would, for the long term, be on “Friends Like Us,” soon to be shortened to “Friends.”

Considering its eventual lofty place in pop culture, it’s a miracle that “Friends,” which premiered 25 years ago on Sept. 22, 1994, got made at all.

The behind-the-scenes story of the sitcom is chronicled in the new book “Generation Friends: An Inside Look at the Show That Defined a Television Era” by Saul Austerlitz (Dutton).

“[NBC executive] Warren Littlefield felt there was a huge untapped audience of younger viewers who wanted to see themselves reflected on screen and didn’t,” Austerlitz tells The Post. “There was a fear of telling stories about first jobs or first serious relationships or roommates — these shared, collective experiences that weren’t being told at the time.”

“Friends” grew out of NBC’s 1993 call to writers for exactly that — programs that would appeal to the younger demographic advertisers craved.

David Crane and Marta Kauffman had met as students at Brandeis University and had been playwrights in New York. In 1990, they created the HBO comedy “Dream On,” about a New York book editor.

For their NBC pitch, the duo mined their life in New York. “They [and their friends] had spent all their spare time together, done everything together, served as a kind of surrogate family,” Austerlitz writes. “What if they put together a show about that?”

The writers assembled a seven-page pitch “detailing the characters, the setting, and some of the adventures they imagined unfolding.”

The show, initially called “Insomnia Cafe,” would take place almost exclusively in a coffee shop, but Littlefield suggested that the characters’ apartments take more prominence and that the friends live across the hall from each other.

David Schwimmer, who’d had a well-regarded guest role on ABC’s “NYPD Blue,” was approached to play Ross, an uptight professor. Schwimmer wasn’t interested in doing more TV and said no. But after reading the script, he relented.

The network, however, wanted Jonathan Silverman. NBC, according to one producer, saw Silverman “as a handsome Jew, one who could pass as a leading man, and Schwimmer was not.”

Lisa Kudrow impressed the “Friends” crew with her guest role on NBC’s “Mad About You,” and was cast as Phoebe, who was “sweet, flaky, a waif, a hippie.”

Courtney Cox was originally pegged to play Rachel, Aniston’s part. But Cox pushed to audition for Monica and landed the role.

Matt LeBlanc was a sitcom veteran, but he may have an accident to thank for his “Friends” casting. He showed up for the audition with a scraped nose, acquired during a fall after a bout of heavy drinking the night before. He so charmed the showrunners with the tale, he “felt the audition had suddenly tilted in his favor.”

The producers looked at several actors for the part of Chandler, an acerbic wise-cracker, including Jon Favreau. They were set on casting Craig Bierko, a stage veteran. He turned down the role, but the producers learned that he’d been running lines for “Friends” with another actor — Matthew Perry — and what they had liked about Bierko was “merely a reflection of Matthew Perry.”

The pilot was filmed by famed sitcom director James Burrows in May 1994.

The responses internally at NBC were lukewarm. One company memo called the show “not very entertaining, clever, or original.” The head of program research loathed it. “Friends” received a “high weak” grade in internal testing. NBC President Don Ohlmeyer was especially concerned that Monica would be seen as a slut for having sex on a first date on the pilot.

Even the titles were controversial. Ohlmeyer hated the footage of the cast cavorting in a fountain. The exec thought it said to the audience, “We’re young, we’re hip, we’re dancing in a fountain and you can’t dance with us.”

He demanded the producers add clips from the show in the intro.

The theme song was penned by musician Michael Skloff, Kauffman’s (now ex-) husband. He’d heard The Beatles’ “Paperback Writer” in the car one day, and thought the “Friends” opener should have a similarly sunny ’60s pop vibe.

Michael Stipe and Natalie Merchant were approached to record the song but passed. The honor went to another Warner Bros. artist, The Rembrandts. (The song hit the top 20 in 1995.)

‘There was a fear of telling stories about first jobs or first serious relationships or roommates.’

Before the pilot was shot, the writers had intended to make Monica and Joey the show’s main romantic couple. But when the showrunners saw that Schwimmer and Aniston had an “indescribable mixture of attraction and loathing and tenderness and brutishness,” “Friends” suddenly became all about Ross and Rachel.

The other characters were also tweaked to better fit with the actors playing them. Monica was made less biting and her trademark OCD was added after the writers spotted Cox straightening the furniture on the set between takes.

Some of the plotlines were mined straight from the writers’ lives. Writer Adam Chase was once persuaded by a beautiful sales clerk to buy a $600 pair of leather pants. The experience was turned into a gag for Ross.

Writer Greg Malins had a friend who jokingly put on every piece of another friend’s clothing. The prank was used by Joey to punish Chandler.

The writers worked exceedingly hard, regularly putting in 14- to 16-hour days.

“My impression was that David and Marta were perfectionists and had to have every line be as perfect as it could be,” Austerlitz says.

(The only time they seemingly fell short was with Season Five’s “The One Where Rachel Smokes.” Crane was disappointed with the episode and asked NBC not to air it. The network refused.)

Despite the internal NBC misgivings, the show was an immediate hit.

The show’s popularity allowed it to attract numerous A-list guest stars, including Brad Pitt and Bruce Willis. Charlie Sheen appeared in Season Two as Phoebe’s boyfriend, but was so nervous, his legs were literally shaking. Sheen had to be pulled aside and given a massage to calm him down.

By the time the show signed off after Season 10, it was a global pop-culture juggernaut. (Ross’ Season Four wedding to Emily had been set in London, in part, to court the UK audience, which had been buying millions worth of “Friends” DVDs.)

Some 52 million American viewers tuned in to bid the “Friends” adieu, the fourth-largest finale audience in history.

The cast would go on to other endeavors but will likely never shake the association with “Friends.”

“We could never leave that stage, metaphorically speaking,” LeBlanc later told Littlefield. “Still can’t. Still on that stage. That will follow us around forever.”

As a result of syndication and Netflix, the series has found a whole new audience of viewers, many in their teens and 20s. Austerlitz says the show offers timeless wish fulfillment.

“This show presents a vision in which you spend all your time with your friends,” the author says. “Even after you’ve gotten married and had children, you’re still having breakfast with your friends every single day.

“That idea that your entire life will revolve around your friends is really appealing.”