The Origins of Sex: A History of the First Sexual Revolution. By Faramerz Dabhoiwala. Allen Lane; 484 pages; £25. To be published in America in May by Oxford University Press USA; $34.95. Buy from Amazon.com, Amazon.co.uk

FOR much of the last millennium Europeans lived under sex laws that would have won the approval of the most austere mullah. In England between the 13th and 16th centuries, extramarital sex was policed with such energy that up to 90% of the litigation handled by church courts was about combating fornication, adultery, sodomy and prostitution. The punishments were often savage. When the Reformation got going in the mid-16th century, the zeal for rooting out illicit sex went up another notch. Harsh new national laws were passed, such as a statute in 1534 that made buggery a capital offence. In 1552 a revision of canon law meant that adulterers could face life imprisonment or exile. Sexual transgressors were often whipped, publicly humiliated and even branded.

A hundred years later things quite suddenly began to change. By the mid-18th century sexual mores in England (and in much of Europe, too) had undergone a revolution, writes Faramerz Dabhoiwala, an Oxford historian who has spent much of the last 20 years researching the subject. This rupture was far more dramatic than anything that happened in 1963 when, according to the poet Philip Larkin, “sexual intercourse began”. Less than 100 years after the execution for adultery of Mary Latham, a young woman in Puritan New England, many people were thinking about sex in ways that would make some contemporary readers blush. The wealthy and powerful proudly and openly displayed their mistresses. A public agog for salacious gossip followed the lives of courtesans and high-society prostitutes (such as the oft-painted Kitty Fisher), and pornography was widely available.

The assumption in early modern England that sexual persecution was essential to good social order was not unlike that of the more conservative Islamic republics today. It was partly rooted in religion and the looming threat of hellfire. It was also a product of patriarchal attitudes that saw women as the property of fathers or husbands. Should a woman have sex with a stranger, her family would feel that a crime had been committed against them.

There were practical considerations, too. For affluent families the sudden arrival of a bastard child could wreak havoc with rules of inheritance. The illegitimate children of the poor were resented as burdens on the community, and there was a constant fear of venereal diseases spread by whores. It was everyone's business to bear down on illicit sex because of its awful consequences. Policing was effective because most people lived in villages or small towns where privacy was unknown.

When and why did things start to change? The latter half of the 17th century saw the start of a backlash against extreme Puritanism, particularly among the upper classes who observed the louche goings on at court, led by the libidinous Charles II. But as Mr Dabhoiwala persuasively argues, the reasons for the first sexual revolution were complex and varied. The migration of people to big cities had made the bonds of traditional morality much harder to enforce, while the explosion of mass-printed media both spread ideas and exploited prurient interest in sexual shenanigans. Exploration also had an influence, as travellers returned with tales of very different sexual cultures.

But the key driver, Mr Dabhoiwala believes, was the spread of religious tolerance and nonconformity, which eroded the church's authority and let people define morality more personally. Samuel Johnson, a high Tory Anglican, spoke for many in 1750 when he opined that “every man should regulate his actions by his own conscience”. His close friend and amanuensis, James Boswell, chronicled his own frequent encounters with whores and musings on polygamy with little show of guilt. For Boswell and many of his contemporaries, morals were “an uncertain thing”. The upper-middle-class members of the Beggar's Benison club in Scotland, founded in 1732, apparently thought nothing of arranging meetings where they could drink, sing and fondle naked women. Such evenings were brought to a fitting climax, as it were, when they would communally ejaculate into a ceremonial pewter platter. The book is rich in anecdotes, funny, touching and seedy.

Yet it would be wrong to view late-18th-century attitudes towards sex as a prototype of our own. Sexual liberation was largely confined to the ranks of well-to-do chaps. It was generally assumed that while it was “natural” for men to pursue sexual opportunity, women were instinctively more virtuous (in complete contrast with the prior belief that women were the more uncontrollably lustful sex). Thus women were seen as vulnerable to male seduction, particularly by unscrupulous rakes who plotted with bawds to ensnare the innocent. William Hogarth's 1732 engravings of “The Harlot's Progress” were wildly popular, as were Samuel Richardson's moralising novels, “Pamela” and “Clarissa”. The number of prostitutes in London grew exponentially, but they came to be regarded less as wicked sirens and more as victims of men's carnal appetites who deserved not punishment but pity—and, when possible, salvation and reform by charitable institutions.

“The Origins of Sex” is a splendidly informative and entertaining book, but Mr Dabhoiwala leaves us with quite a few frustratingly loose ends. He has little to say, for example, about contraception, which was central to the sexual revolution of the 1960s. Sheaths of various kinds became popular in the 18th century, but libertines such as Casanova saw them more as protection against disease than as a form of birth control. What women thought about contraception is left blank. And by restricting himself to the period running roughly between 1600 and 1800, the author is able to bypass the late-Victorian return to sexual discipline, which lingered well into the last century. The difference, he would say, is that even the most prudish Victorians saw sexuality largely as a private matter, which the state should neither judge nor attempt to regulate. If only young Iranians were so lucky.