A dear old dad left behind a final, unthinkable request for his gay son: get married — to a woman.

The edict surfaced in the will of Manhattan businessman Frank Mandelbaum, who specified that none of his money should go to any offspring his son Robert might have if he “not be married to the child’s mother within six months of the child’s birth.”

Frank Mandelbaum, 73, died in 2007, and his will prompted Robert Mandelbaum, a Manhattan Criminal Court Judge, to argue in a court battle over the estate that his longtime partner Jonathan O’Donnell is the only “mother” their 16-month-old son, Cooper, knows.

The couple married shortly after Cooper’s birth via a surrogate, entitling the child to a share in a $180,000 trust set aside for Frank Mandelbaum’s three grandkids, Robert declared.

The Manhattan Surrogate’s Court has yet to approve a settlement to ignore Frank Mandelbaum’s demand as discriminatory and against New York law.

The settlement is the only way to solve the dispute over Cooper, Robert Mandelbaum claims in court papers, because the will “imposes a general restraint on marriage by compelling Robert Mandelbaum . . . to enter into a sham marriage” — which he says violates state law supporting marriage equality.

A law guardian appointed to look out for Cooper’s interests agreed that there are “significant public policy reasons” for ignoring the dead dad’s dictate.

“Requiring a gay man to marry a woman . . . to ensure his child’s bequest is tantamount to expecting him either to live in celibacy, or to engage in extramarital activity with another man, and is therefore contrary to public policy,” Anne Bederka wrote in court papers. “There is no doubt that what [Frank Mandelbaum] has sought to do is induce Robert to marry a woman.”

The child’s birth complicated an already sour dispute over the handling of Frank Mandelbaum’s estate, prompting Mandelbaum’s wife, Ann Freeman, to say in court papers that Robert “alleged that he had a son from a homosexual relationship which he believed should be a beneficiary . . . My husband’s will specifically prohibited such a child from becoming a beneficiary.”

Frank Mandelbaum, the founder of ID verification company Intellicheck, was well aware that his son was gay, Robert claimed in court papers, noting that his partner was included in family dinners and vacations.