At Christmastide you can’t escape from the fact that Christianity centres on the birth of a child, and glories in it. But Christians say that this Jewish baby from 2,000 years ago is also the supreme God, and then it gets complicated.

Birth generally involves sexual encounter, all messy and sweaty: what about this one? Did Jesus have two human parents? Well, he certainly grew up with a mum and dad, Mary and Joseph; but the story we hear in church at Christmas, amalgamated out of two different accounts in two of the four gospels, suggests that somehow Joseph didn’t get involved in the initial process of parenting, and that Mary had remained a “virgin”.

Yet those gospel-writers, Matthew and Luke, seem confused. They set out, at great length, Joseph’s family tree, which suggests that he was Jesus’s biological father – otherwise why would they bother with the genealogy?

Maybe because of this shaky knowledge of Jesus’s parentage, Christianity has tied itself up in knots about sex and marriage: it must often seem to outsiders that Christians do little else but argue about these questions. And frequently, confident Christian assertions about sex are made without understanding the history behind it all.

Matthew tries to prove Mary was a virgin by referring his story back to an ancient Hebrew prophecy from Isaiah, that “a virgin shall conceive and bear a son”. Yet Matthew was writing in Greek, and unfortunately the original Hebrew didn’t talk about a “virgin” at all, just a “young woman”. On that slight shift in translation, Christianity built a great deal.

Around a century after the first four gospels were composed, new Christian writings, also claiming to be gospels, began to emphasise Mary’s virginity, removing any taint of sex from her story. One of these is the gospel of James. It was never regarded as an official gospel, but it was hugely popular in its day for filling in the bits of a very patchy New Testament tale. It tells Mary’s story from her birth through to the birth of Jesus, and one of its main aims is to emphasise that Mary didn’t just start out a virgin – she stayed a virgin. So in a key part of the text, a midwife examines Mary after childbirth and exclaims in astonishment: “Behold, a virgin hath brought forth: which nature doth not allow.”

The Nativity (scientifically accurate version) | Dean Burnett Read more

This “gospel” has another new departure: the idea that God had already intervened not just in the birth of Jesus, but in the conception of Mary herself. James tells us that Mary’s mother (called for the first time Anna, another detail not in the Bible) was infertile.

Then an angel appeared to Anna, saying: “Anna, Anna, the Lord has heard your prayer. You will conceive, and bear a child, and the child will be famous throughout all the world.” And immediately Anna fell pregnant with Mary. This is the origin of the Roman Catholic idea that Mary, let alone Jesus, was conceived without sin: the “immaculate conception”.

Take note: we’re not dealing with the original four gospels here. There are references in those biblical gospels to Jesus having brothers and sisters – which sounds as if Mary at the very least didn’t stay a virgin. Christians began to explain them away as Jesus’s cousins – or Joseph’s children by a previous marriage. As a result, Christianity came widely to accept Mary’s perpetual virginity: she stayed a virgin. This means that the most important marriage in the Christian story didn’t involve physical sex at all, which makes for a confused start to any Christian theology of marriage.

Christianity’s problem with sex goes back to these first centuries of its history, when early Christians turned sex from a biological necessity into a vice; from a pleasure into a sin. Christians have been struggling with the fallout ever since.

According to the gospels, Jesus Christ had very little to say about sex. He did insist on monogamy in marriage, and he decreed that there should be no divorce (something about which Christians began disagreeing with him straight away – including the apostle Paul). But beyond those two pronouncements, Jesus said virtually nothing – nothing, for instance, about homosexuality.

One gospel story, more than any other, sums up his attitude towards sex (John 8:3-11). Jesus was teaching in the Jerusalem Temple, where the Dome of the Rock now stands, when a group of men dragged in a woman caught in the act, they said, of adultery. They asked Jesus whether they should stone her to death – the ancient Jewish penalty. But all he said was: “He that is without sin, let him cast the first stone.” And when they’d all shuffled off looking sheepish, all he said to her was to go off and sin no more.

That is a story of forgiveness and mercy. Jesus was very hot on forgiveness and mercy. It would be nice if Christians were too.

• Diarmaid MacCulloch is emeritus professor of the history of the church, University of Oxford