Harvard University unfairly withheld a Texas immigrant’s degree after he was falsely accused of sexual misconduct, he charges in a lawsuit.

Damilare Sonoiki’s rags-to-riches story brought him from Lagos, Nigeria, to Houston as a kid before he won a spot at a top Virginia boarding school, and eventually entry into Harvard, according to court papers.

He went on to work for Goldman Sachs, before switching gears to write for television shows like “The Simpsons,” and “Black-ish.”

Sonoiki, 28, blames his misfortunes on his poor treatment at Harvard, where he was weeks from graduating in May 2013 when a dean told him he was “the subject of informal complaints of alleged sexual assault,” he recounts in his Massachusetts Federal Court filing.

Sonoiki, who denied assaulting anyone, participated in his graduation but was not given his degree as the university investigated claims from three women.

The school’s administrative board conducted an unfair inquiry “behind closed doors,” failed to give Sonoiki an attorney, and didn’t even tell him who his accusers were, he charged in court papers.

“I didn’t really question Harvard. I just figured they’d get to the bottom of this,” he said.

But the probe dragged on. “Your life just kind of ends up in limbo. You can’t get a job because, you don’t have a degree; you can’t get a degree because you’ve been kind of branded.”

Sonoiki pleaded guilty in the insider trading scheme that helped NFL linebacker Mychal Kendricks net more than $1 million. Harvard declined comment on the litigation.