Shakespeare was never a 16th-century Moorish general in ­Vienna, but he had the temerity to write about one in “Othello.” George Eliot was never a crabbed and megalomaniacal mythologist, but she dared to create the gloriously appalling Mr. Casaubon in “Middlemarch.” And Leo Tolstoy wasn’t an adulterous woman — ­indeed, he was a man — yet he gave the world one of the most compelling and memorable portraits of female adultery in “Anna Karenina.”

Are such feats of imaginative creation and habitation now to be scrutinized by the gender police and social justice warriors?

The case of the American novelist E.J. Levy, celebrated author of “Love, In Theory” and “Tasting Life Twice,” an anthology of lesbian fiction, makes me wonder.

Levy has also written a forthcoming historical novel titled “The Cape Doctor.” At least, I hope it’s forthcoming. The book is about a real-life character, James Barry, née Margaret Ann Bulkley, a 19th-century, Irish-born army surgeon who practiced in Cape Town and lived as a man.

It’s that last fact, of course, that gives Barry’s story its dash of hot sauce. As one news report tells it — and note, please, the use of the participle “assigned” — “Barry was assigned female at birth but lived his entire adult life as a man. In the past, he was seen as a woman who donned men’s clothing so he could become a doctor, but LGBTQ historians now regard him to be a transgender man.”

And since “LGBTQ historians” so regard him, you had better, too. Or else.

What we have here is a sort of back-parlor version of the conflagration that has consumed the tennis great Martina Navratilova these past weeks.

Navratilova, trailblazing lesbian though she is, had the temerity to challenge the new popularity — and physical dominance — of male-to-female transgender athletes in women’s sports.

The “trans” Twitter mob came for her (ironic, given that her coach was Renée Richards, né Richard Raskind), and various ­social justice organs denounced her for her thought crimes.

Now it’s Levy’s turn to face a Maoist-style struggle session. The novelist sparked the yapping ire of the social justice crowd by referring to Barry née Bulkley as “she” in her novel.

News of this outrage has precipitated a frantic response in the Twittersphere. Hundreds upon hundreds of triggered crybullies have besieged Levy’s publisher, Little, Brown.

“Please understand the anguish you are causing,” wrote one wounded soul. “This may be a fun, imaginative romp for the author, but it amounts to [the] theft of one of our very few well-documented transgender ancestors. Do not steal our history.”

Little, Brown fretted, issuing one hand-wringing response, and then a “revised” one assuring the book-buying public that it was working with Levy to “publish her novel with sensitivity to the issues that have been raised, including the use of the proper pronouns to describe Dr. Barry’s embodiment.”

The proper pronouns, eh?

For her part, Levy dismissed her critics as “policing gender” and said that “there’s no evidence Barry considered herself trans.”

She also described the outcry as the work of a “troll mob,” which seems about right to me. Reporting the story under the headline “Writers want this book canceled for misgendering its protagonist,” a website called The Daily Dot seemed to chastise Levy for abetting “some recurring themes in anti-trans rhetoric online.”

“Trans-exclusionary radical feminists,” the staff writer Gavia Baker-Whitelaw explains, “often theorize that trans and nonbinary people are just rebelling against gender norms, and that their gender identity is not valid.”

Deep waters!

I won’t wade into them, other than to advise Levy to ignore this sudden wave of ­online fury. It is in the nature of Twitter storms to be as ephemeral as they are vicious and indiscriminate.

Do what Tucker Carlson just did: Stand up to the mob. Be a novelist. Imagine characters that are unlike you but say something about the human condition.

Just say “No!” to censorship from these new self-appointed guardians of virtue.

Roger Kimball is publisher of ­Encounter Books and editor of The New Criterion, from which this column was adapted.