Pamela Anderson and Tommy Lee’s infamous sex tape nearly cost the “Baywatch” icon her job.

In the new docuseries “After Baywatch: Moment in the Sun,” “Baywatch” co-creator and producer Michael Berk revealed that there were discussions about removing Anderson, 57, from the hit NBC series after her sex tape with Lee, 61, leaked in 1996.

“When Pam’s sex tape came out, the studio said, ‘Look, write her out of a couple of episodes, we’ve got to figure out what we’ll do with this, this is a disaster,’” Berk recalled.

Anderson became a beloved celebrity from her role as C.J. Parker on “Baywatch” — but her whole life changed because of the notorious sex tape scandal.

The leaking of the home movie, shot by Lee on his honeymoon with Anderson between 1995 and ’96, made Anderson even more famous, to the point where it affected “Baywatch” in ways the creators and producers didn’t expect.

“The next episode aired got twice the ratings,” Berk said. “It just shot up in the ratings.”

Anderson, who got divorced from Lee two years after their sex tape leaked, looked back on the scandal in an unaired-interview that was featured in the doc.

“It was stolen property,” she said. “It was two crazily naked people in love. We were naked all the time and filming each other, being silly.”

“But those tapes were not meant for anybody else to see,” Anderson added. “I have not seen it to this day, it was very hurtful.”

Anderson and Lee’s sex tape was stolen by Rand Gauthier, who claimed the couple had not paid him for $20,000 of electrical work he did at their Malibu residence.

He created a website selling bootleg copies of the video, and pretty quickly the footage spread far and wide. According to Rolling Stone, the video made more than $77 million worldwide.

Anderson filed a lawsuit against Internet Entertainment Group, the company that distributed the sex tape. She and Lee later reached a settlement with the business.

The scandal was incorporated into the 2022 Hulu miniseries “Pam & Tommy” starring Lily James and Sebastian Stan. Anderson reportedly refused to watch the show.

Anderson and Lee had an intense and volatile relationship that involved altercations with the paparazzi. They welcomed two sons, Brandon Thomas Lee, 28, and Dylan Jagger Lee, 26, before their divorce.

“The relationship between Pam and Tommy Lee complicated things,” Berk said in the doc. “It complicated her life. It complicated our lives.”

He went on, “I like Tommy Lee. I liked them together. Pam loved Tommy. He was terrific. But there was this window of time where perhaps they were having problems in their marriage, or issues, or whatever it was.”

Berk also recalled how Lee got jealous about Anderson’s relationships with her co-stars on the show.

“There was one incident where Tommy Lee came into her trailer, and she was out doing a scene with [David] Chokachi, and he was getting more and more upset that she wasn’t coming and he kind of trashed her trailer.”

Anderson didn’t participate in the “Baywatch” doc and also skipped the premiere on Monday along with OG star David Hasselhoff.

The “Home Improvement” star previously opened up about the wild life she’s had in her Netflix documentary, “Pamela: A Love Story,” and her memoir, “Love, Pamela,” which both came out last year.

She said in her doc that she “blocked out” her stolen sex tape and that reliving the year it got leaked made her feel “sick.”

Anderson also said that with the release of both projects, she wanted to “take control of the narrative for the first time.”

“After Baywatch: Moment in the Sun” is streaming on Hulu.