More than 3,000 women and almost 900 men — that’s the number of lovers the main protagonist in Ihara Saikaku’s 1682 novel “Koshoku Ichidai Otoko” (“The Life of an Amorous Man”) tallies up as he reminisces. Saikaku, born in Osaka in 1642, became a renowned poet who wrote about the fluid, open sexuality of Edo Period (1603-1868) pleasure quarters with a startling lack of inhibition: In the 1685 collection of stories “Koshoku Gonin Onna” (“Five Women Who Loved Love”), he explores the love lives of feisty females; in “Koshoku Ichidai Onna” (“The Life of an Amorous Woman”), published in 1686, he includes a brief lesbian scene; and then there is “Nanshoku Okagami” (“The Great Mirror of Male Love”), a 1687 collection that focuses exclusively on love between men.

The sexual openness of Ihara’s characters seems to be profoundly out of place in contemporary conservative Japan. Today, the recognition afforded to the LGBT community is hotly debated in the country, and though traditionally conservative nations such as Ireland have legalized same-sex marriage, Japan is lagging behind. A recent legal ruling even rejected the right of partners (in practice, women) to keep their surnames after marriage, as a means of protecting “traditional family values.”

Though Japan’s current social conservatism appears at odds with the West’s liberalizing tendencies, it’s also at odds with the nation’s own past. Writers, stretching from Ihara to modern authors such as Natsume Soseki and Yukio Mishima, have often approached sexuality with curiosity.

When Mishima sat down to pen his iconic 1949 novel “Kamen no Kokuhaku” (“Confessions of a Mask”), he declared that he would be writing a novel that explored the taboo of homosexual desire like no other — and only faintly foreshadowed by the works of European writers such as Andre Gide and Jean Cocteau. Mishima was not exaggerating: this frank “confession” of homosexual and sadomasochistic desires caused a sensation in Japan. Employing the analysis of European sexologists such as Havelock Ellis and Magnus Hirschfeld, Mishima claimed he was writing about something called “sexual inversion” and that his confession would be “the most effective form of psychotherapy.” How did Japan, which had once been so accepting of nanshoku (male homosexuality), become so disconnected from its sexually liberal literary past?

In Meiji Era (1868-1912) novels, homoerotic subjects were treated extremely subtly. For example, very few readers notice that the male protagonists of Natsume Soseki’s 1907 novel “Nowaki” are described as “lovers.” Looking back, the literature of the earlier Edo Period bristles with homoerotic desire.

RELATED STORIES Mishima and the maze of sexuality in modern Japan

Take Ueda Akinari’s short ghost story “Kikka no Chigiri” (“Chrysanthemum Tryst”), published in 1776. In it, a samurai makes a promise to return by the time of the Chrysanthemum Festival to visit a Confucian scholar who has nursed him back to health, but he finds himself detained in a far off place, unable to fulfill the promise. The solution? He kills himself and allows his liberated ghost to make the appointment on his behalf. Is this a noble tale of samurai honor or of two men whose love is so intense that one would rather die than disappoint the other? Given that the chrysanthemum was a symbol of homosexual intercourse in Japan, it’s safe to assume the latter.

In the Judaic, Christian and Muslim traditions homosexuality is proscribed, but in Japan, where the Buddhist and Confucian ideals of deference, loyalty and dedication were promoted, same-sex relationships were accepted. Since the Heian Period (794-1185), Japan’s numerous Buddhist temples and monasteries — densely populated with men and often isolated from the rest of society — were widely reputed as hotbeds of same-sex relationships.

The homosexual bonds between samurai meanwhile, nurtured in the relationships between a wakashū (adolescent boy) apprenticed to an older man, were considered ennobling to both and the foundation of lifelong friendships — and used to bolster existing power relationships, giving young samurai added motivation to lay down their lives for their lord. One of the most famous examples, later depicted in the kabuki plays of writers such as Tsuruya Namboku IV, was the devotion of the 17-year-old youth Mori Ranmaru (1565-1582) to the brutal warlord Oda Nobunaga (1534-1582). It was so intense that he died alongside his lord — possibly by his own hand.

When wakashudō (the pursuit of young boys) fanned out to the more commercially minded and fun-loving middle class in the Edo Period, the number of male prostitutes soared and young kabuki actors often moonlighted as prostitutes, desired by both men and women.

There is a temptation though to see the sexual attitudes of this period as relaxed and open compared to later repressions of the Meiji Era. But it should not be forgotten that this seeming “liberalism” was operating within highly prescriptive power structures controlled by a patriarchy. Relaxed attitudes to sex and gender did not extend to anything that might have disrupted the social order — women were subservient to their husbands and adultery was a criminal offense punishable by death.

The oppressive aspect of Edo Period morality is acutely depicted in the bunraku and kabuki plays of Chikamatsu Monzaemon (1653-1725). Also, the horrific consequences of adultery have been depicted in classic films, such as Kenji Mizoguchi’s “The Crucified Lovers” (1954), based on a 1715 Chikamatsu’s play.

During this period, so-called pleasure quarters were demarcated as the only acceptable areas for men to relieve sexual frustration and energy with prostitutes before returning to the fold of social conformity. Falling in love with an indentured prostitute often had fatal consequences — the plot of many tragic works including Chikamatsu’s 1720 play “Shinju Ten no Amijima” (“The Love Suicides at Amijima”).

In the name of order, the ruling shogunate watched these quarters closely to ensure they did not exceed certain bounds. The Edo Period saw a long stream of edicts by the shogunate proscribing immoral behavior, including the banning of licentious books and art works

Writers in Japan have been exploring the complexities of sexual identity for centuries. But in the late 19th century, as the nation opened itself to the West, expressions of sexuality began to close and literature gradually aligned with the norms of the primly moralistic and intensely homophobic Victorian novel.

As traditional sexual liberalism was submerged under an imported code of repressive sexual morality, Japanese literature underwent profound changes. And as the writers shifted their focus, the entire nation’s understanding of its colorful sexual past began to transform.

This is the first installment in a three-part series on sexuality in Japanese literature. The second part of this series will run on Dec. 18. Damian Flanagan is the author of “Yukio Mishima” (Reaktion Books, 2014) and “The Tower of London: Tales of Victorian London” (Peter Owen, 2004).