The heir to a $100 million ice cream fortune paid private investigators nearly $9 million to spy on his estranged wife, but now he wants his dough back — because two of them raped her, a new lawsuit charges.

Millionaire David Smith — who has since reunited with his spouse, Susanne Gold-Smith — says he paid $140,000 a week for months to the International Investigative Group to trail his then-estranged wife.

Nine private investigators followed Gold-Smith everywhere from Rod Stewart concerts to casinos and nightclubs, according to Smith’s Nassau County Supreme Court suit.

But while the gumshoes were on Smith’s payroll, two of them sexually assaulted his wife, and three more coerced her into sexual foreplay, court papers claim.

The lawsuit describes one alleged instance in which investigator Richard Custodio entered Gold-Smith’s Plainview, LI, home in January 2018 at 12:30 a.m., went straight to her bedroom, “climbed on top of her and initiated unwanted, invasive sexual relations.

“Gold-Smith ultimately surrendered to Custodio’s sexual demands, as she was afraid to resist out of fear of retribution,” the court documents charge.

Custodio denies the allegation in his response papers.

Smith’s suit also alleges a similar scenario involving former NYPD cop-turned-PI Yanti Greene.

The suit claims Greene lured Gold-Smith into his car on April 24, 2018, behind a Fairway in Plainview, “removed Gold-Smith’s pants, climbed on top of her and initiated invasive sexual relations.”

The suit says that a month later, Greene drugged Gold-Smith and raped her in his car while recording the attack on his smartphone in the same supermarket parking lot.

In court papers responding to Gold-Smith, Greene, who is acting as his own lawyer, claims she is the one who raped him.

Gold-Smith made “constant sexual and perverted advances” that Greene shunned for months, court documents allege.

Gold-Smith finally tracked him down to the desolate shopping center parking lot on April 24, 2018, when he was off duty and raped him and forced him to engage in oral sex with her, Greene claims.

A month later, Gold-Smith allegedly sought him out at the same location, climbed into his car, took off her clothes and climbed on top of him while he was seated in the driver’s seat.

“She then got off of the defendant, climbed back into the rear seating area and forcefully pulled the defendant into the rear seating area with her, then forcefully unbuckled and unzipped the defendant’s pants” and forced the defendant to have sex with her, alleges Green, who admits to videotaping the encounter with his phone.

As for Smith’s suit, he further alleges that in addition to his wife being raped, she was coerced into heavy petting sessions with three other PIs hired through IIG.

The three private detectives have denied the allegation.

No criminal charges have been filed in any of the cases.

Smith, whose father once ran the Chipwich and Eskimo Pie empires, paid IIG $8,838,845.74 to track his wife from February 2016 to January 2019 and wants the full sum returned with interest.

He also is demanding an additional $30 million for alleged fraud and gross negligence.

IIG has denied the allegations in court papers. Its owners, David and Lisa Ribacoff, declined to comment to The Post. The company and Custodio are countersuing Smith for attorney’s fees.

Gold-Smith and her husband initially split in 2016. Last year, before the couple got back together, Gold-Smith sued her husband for $25 million, claiming he demanded sex in exchange for visits with their son.

Smith’s father, Richard E. Smith, was CEO of CoolBrands International, the company that once owned Chipwich and Eskimo Pie.

Her lawyer declined to comment regarding the new lawsuit, while Smith’s attorney didn’t return a request for comment.