Sparta. 610BC. A group of teenage girls are carrying a plough through the night, like a team of oxen. Teenage girls, invol-ved in some kind of ritual, processing towards a mountain ridge. They are singing a beautiful song, a work of art, full of obscure allusions and some familiar names from ancient myths: Helen's devoted twin brothers, Castor and Pollux, "Aphrodita", the goddess of love, the dangerous, teasing Sirens. But now the girls seem to be calling out to each other, strange, old-fashioned names: "Wianthemis", "Philulla", "Astaphis", "Hagesichora". And they are flattering each other - "lovely Wianthemis". No, something more than that. Flirting. "If only Astaphis were mine, if only Philulla were to look in my direction". Hints, even, of sexual jealousy: ". . . but I mustn't go on, for Hagesichora has got her eye on me."

Another location: the island of Santorini, an odd part-circumference of rock. A hard sound, chink, chink. Metal chipping out stone. High on a precipitous altar-dotted promontory, a man is surrounded by a small crowd of youths. They are watching him, as the sweat pours off him, chiselling strange, old-fashioned letters into the lava. "In this place, as Apollo is my witness, Crimon had sex with the son of Bathycles..." He has nearly finished his inscription now, one more - unexpected - word... "A-D-E-L-P-H-E-O-N, his brother."

Fast-forward a couple of hundred years. Athens in the age of Plato. A big city. A solemn trial. A man accused of attempted murder. He begins to tell his side of the story, how he got into a fight with some worthless creature called Simon. "You see we both lusted after the boy Theodotus..." he explains to the august judges. They nod sympathetically, as if all is now clearer.

The secret of Greek homosexuality has only ever been a secret to those who neglected to inquire. The Greeks themselves were hardly coy about it. Their descendants under the Roman empire were amazed to read what their ancestors had written centuries earlier, drooling in public over the thighs of boys, or putting words into the mouth of Achilles in a tragic drama, as he remembered the "kisses thick and fast" he had enjoyed with his beloved Patroclus. The Romans certainly noticed what they called the "Greek custom", which they blamed on too much exercising with not enough clothes on. Christians mocked a people who worshipped gods who kidnapped handsome boys like Ganymede, or who, like Dionysus, promised a man his body in exchange for information about how to get into the underworld. Nor was it forgotten in the Middle Ages, when Greek Ganymede became a codeword for sodomitical vice.

At the end of the 17th century the great classicist Richard Bentley knew well enough that the Greek word for a male "admirer", erastes, indicated a "flagitious love of boys". And in 1837, when Moritz Hermann Eduard Meier was asked to contribute a book-length article on the subject to a giant encyclopaedia of arts and sciences, he made no bones about it: "The spiritual elements of this affection were always mixed with a powerfully sensual element, the pleasure which had its origin in the physical beauty of the loved one."

And yet there was always another side to the story. We hear of laws that punished men who "mixed with" or even "chatted" with boys. Xenophon, who knew Sparta better than anyone, says that the Spartan lawgiver had laid down that it was shameful even "to be seen to reach out to touch the body of a boy". Slaves called "pedagogues" - paidagogoi - were employed by Athenians to protect their sons from unwanted attention, and by Plato's time there were some people who had "the audacity to say" that homosexual sex was shameful in any circumstances. Indeed Plato himself eventually made so bold. At one time he had written that same-sex lovers were far more blessed than ordinary mortals. He even gave them a headstart in the great race to get back to heaven, their mutual love refeathering their moulted wings. Now he seemed to contradict himself. In his ideal city, he says in his last, posthumously published work known as The Laws, homosexual sex will be treated the same way as incest. It is something contrary to nature, he insists, and although there won't be laws against it, nevertheless a propaganda programme will encourage everyone to say that it is "utterly unholy, odious-to-the-gods and ugliest of ugly things".

For these and other reasons there has long been debate about the true nature of this Greek custom - what the Greeks called eros, a "passionate life-churning love", or philia, "fond intimacy". Was it essentially sublime or sodomitical? A source of anxiety or a cause for celebration? Sometimes the Greeks seemed to approve of it wholeheartedly, even to suggest that it was the highest and noblest form of love. And other times they seemed to condemn it. Sometimes the ideal seems to be a spiritual, passionate but unconsummated "Platonic" love, like that much praised by Plato's Socrates. It was this notion that allowed Ganymede, ancient mascot for the vice unmentionable among Christians, to appear on the doors of St Peter's in Rome, where, amazingly, he remains, or as the emblem of "piety" in Christian picture-books. So popular were such prints of Ganymede in the Catholic Baroque that Rembrandt painted a harsh rejoinder. Instead of sublimely rising, his Ganymede is kicking and screaming, dragged off in incontinent terror.

But the image of an idealised non- sexual same-sex love was still powerful enough at the end of the 19th century for Oscar Wilde to think it a good idea to invoke the Greek example - "that deep spiritual affection that is as pure as it is perfect" - in his defence when charged with sodomy. Some members of the audience in the courtroom clapped and cheered, although there was nothing very spiritual about the sensual love unblushingly described by poets such as Aeschylus, Theocritus and Solon - as Wilde knew better than anybody.

A number of solutions have been proposed over the years to account for these apparent contradictions. Meier and others appealed to changes over time. First they identified in the distant past - the age of heroes - a rather extreme form of buddydom, comrades-in-arms like Achilles and Patroclus in Homer's Iliad, not lovers in the modern sense, nor in any other sense either, just extremely good friends. When later more homosexually inclined Greeks added kisses - and more - to the relationship, they had simply misunderstood what Homer intended. The origins of the true (in)famous Greek Love should be placed, these scholars suggested, about 100 years later, in the years before 600BC, in a virile and passionate and educational appreciation of youthful male beauty that was very quickly "corrupted" or "poisoned" by sensuality and indeed sex.

In 1907, however, Erich Bethe turned this narrative on its head. He had heard rumours of some strange homosexual customs discovered by missionaries in Papua New Guinea; boys there were inseminated as part of an initiation rite in order to help them grow into men. Perhaps this is how Greek homosexuality started, he said, with primitive tribes like the Dorians (cultural ancestors of the Spartans) in the second millennium BC using buggery to transmit manly essence into the younger members of the tribe, a quasi-magical ritual. This, he suggested, was what was being commemorated in the recently rediscovered rock inscriptions on Santorini, a Dorian colony. Crimon was calling upon the god Apollo himself to bear witness to "a holy act in a holy place" - a kind of "marriage". From the Dorians the ritual spread throughout Greece, but the magical essence of the act was lost along the way and buggery was supplanted by something more educational. Bethe's gross analysis was not very popular with his peers, and a pantheon of classicists lined up to dismiss his theories.

Then in 1963, Kenneth Dover, a distinguished scholar, was reading the Observer. A student of Plato, Aristophanes and early Greek poetry, Dover had long been troubled by the "Problem in Greek Ethics". His attention was drawn to an article about double standards in modern sexual morality - how boys were encouraged to pursue girls, and only added to their reputation if they managed to score, whereas girls were encouraged to resist their advances or else be condemned as "whores". Suddenly he realised that "practically everything said during the last few centuries about the psychology, ethics and sociology of Greek homosexuality was confused and misleading". The key point, he decided, was that human beings have always had very different attitudes towards the passive and the active roles in sex. Sex is an intrinsically aggressive act, he suggested, a victory for the penetrator. Hence, if you changed the genders in ancient Greek texts you discovered exactly the same kind of double standard the author of the Observer article had noted. "Admirers" (erastai) - whom Dover assumed were "active" - were encouraged to score and were even seen as more manly the more notches they collected on the bedpost, whereas for their poor beloveds (eromenoi) - whom he assumed were sexually "passive" - the sexual act was intrinsically humiliating and degrading. No wonder the Greeks were in two minds about homosexuality.

This solution to the problem was not in fact original to Dover. AE Housman had suggested something similar in an article he wrote in 1931. But Housman's observations, which alluded (tellingly) to his experience of the macho homosexual attitudes of the "plebs of Naples", were tucked away in a German academic journal, and were in Latin. Dover's, on the other hand, were published in paperback in his Greek Homosexuality (1978), and not merely in plain English but even in the coarser variety: "Fuck you", "I'll be fucked". Although Dover had advertised the aim of his book as "modest and limited", a mere launching-pad "for more detailed and specialised exploration", his modern solution to the age-old problem was gratefully received by academics in every field, not least when Michel Foucault, the French post-structuralist historian of sexuality, gave it a glowing review, creating the impression that this methodologically old-fashioned Oxford don was some kind of pioneer of post-modern studies.

Making up for lost time, classicists rushed to re-interpret, even to re-translate, their texts into more graphically sexual terms, as if afflicted by a kind of "sodomania". Pericles, for instance, had asked Athens's warrior-citizens to behave like erastai of their city, ie to act like her self-sacrificing and besotted devotees. After Dover, this exhortation sounded more dangerous. Modern commentators now worried that Pericles was telling Athenians "Sod Athens!" and wrote long articles trying to explain how this could be possible.

The reason Dover's solution to the problem was embraced so eagerly was that it was so neat. It was not just that the weird old Greeks were transformed into something much more familiar - with a 1960s sexual morality and even the same modes of swearing - but that Dover seemed to have provided a compelling answer to the question of how they could be so "gay" in the first place. They were not really being sexual at all but "pseudo-sexual". Greek homosexuality was like adolescent horseplay, frat-house initiations or prison rape. It was like male monkeys presenting rumps to their superiors (This was also a time when Desmond Morris's The Naked Ape and its sequels were topping international bestseller lists). The only difference was that these human apes had taken this universal gesture of sexual domination a little further than their primate cousins.

There were problems with this neat theory, however. In the first place, there was little positive evidence to support it. It was not just that Dover's translations were sometimes simply wrong - the Greeks did not in fact go around saying "fuck you", as Housman, for one, could have told him - nor that the ancient Greeks talked of sex not as an act of aggression, but rather as a "conjoining" or "commingling" (if a father dreams of having sex with his absent son it is auspicious, says one ancient writer, reassuringly, since it means they will soon be reunited).

The main problem was that the Greeks did not seem terribly concerned with the ins and outs of sexual positions at all, details which for Dover were critical. Like the Victorians, the Greeks were being coy, he suggested: their silence on the matter only proved its importance. All this lovey-doviness was simply a cover for their true anxiety about "homosexual submission". He decided he would have to supply his own more detailed texts, "translating" the innocent-sounding discussions in Plato's Symposium, for example, into something more graphic: "Acceptance of the teacher's thrusting penis between his thighs or in his anus is the fee which the pupil pays for good teaching".

Was it possible that the Greeks had got the relationship between Achilles and Patroclus so badly wrong, that a peculiarly same-sex-loving culture had simply chanced upon a passionate same-sex relationship at the heart of its foundational text? Surely that was more than fortuitous. Indeed some lines in the Iliad had seemed so overheated to later generations that they had excised them as inauthentic additions, not because they indicated homosexual love, but because they implied a particularly degenerate and extreme kind of passion that was considered unworthy of the dignity of warriors and inappropriate to the grandeur of the epic genre. And if Homer's Greeks knew nothing of homosexuality, how had it managed to spread so far and so fast and so variously in the space of a couple of generations? And then, of course, there was the question of the girls. How did lovely Wianthemis, Astaphis and Philulla fit into this gestural homosexuality of penetration and domination? What of Sappho and the lady-loving ladies of Lesbos? All-in-all, Dover's solution caused more problems than it solved.

So how do we begin to make sense of this truly extraordinary historical phenomenon, an entire culture turning noisily and spectacularly gay for hundreds of years? When I first embarked on the research for my book The Greeks and Greek Love I was not expecting any easy answers, but I did not expect it would be quite as hard as it turned out to be, and take so long as it ultimately did. In fact, it was 10 years later that I finally felt ready to write a conclusion, and it was the longest chapter in the book. I started to think of the phenomenon as a great big Gordian knot at the heart of Greek culture, tying lots of things together but extremely difficult to unravel - "The knot was made from the smooth bark of the cornel tree, and neither its end nor its beginning was visible." Alexander the Great had dealt with that particular knot by slicing right through it with a single blow. But the first lesson I learned about my own particular knot was to stop looking for a single neat solution to a homogeneous phenomenon.

"Ancient Greece" was in fact a constellation of hundreds of rivalrous micro-states, with their own calendars, dialects and cults - and their own local versions of Greek homosexuality. These revealed very different attitudes and employed very different practices: "We Athenians consider these things utterly reprehensible, but for the Thebans and Eleans they are normal." Part of the problem (for the Athenians) was that the men in these communities seem not only to have engaged in public "marriages" but that in these places same-sex couples fought together in battle and slept with each other afterwards, a clear reference to the famous "Sacred Band" or "Army of Lovers".

But there was more to it than that. The males of Elis, in particular, the guardians of Olympia - the holiest shrine in Greece - seem to have got it on together in a particularly "licentious" way. Unfortunately none of our sources could bring himself to say what was so licentious about it: "I will not say it", "I pass over it". There are hints, however, that their sexual transactions were shockingly "straightforward" and did not involve any preliminary courting; and one particularly illustrious Elean, Phaedo, a member of the aristocracy, was said to have served as a male prostitute in his youth, "sitting in a cubicle", waiting to serve whoever walked in. Was this a garbled allusion to the "sanctioned lust" of Elis?

The "peculiar custom" of the Cretans, on the other hand, involved an abduction and a tug-of-war over a boy, a two-month-long hunting expedition, lavish gifts, the sacrifice of an ox and a great sacrificial banquet, at which the boy formally announced his acceptance or not of "the relationship". Thereafter he got to wear a special costume that announced to the rest of the community his new status as "famed". Our evidence for this elaborate ritual comes from a general account of the Cretan "constitution". When the sources compare and contrast Athenian homosexuality with, say, Theban or Spartan homosexuality, they are not referring to undercover reportage - "My night spent with the Army of Lovers: The secrets of the Sacred Band revealed"; nor to surveys of contemporary attitudes - "Do you think it is A. shameful; B. quite shameful; C. not very shameful at all to be seen to reach out to touch the body of a boy?" They are talking rather of specific visible practices and institutions, repeatedly referred to as "customs", "laws", or even "legislation made by lawgivers".

These local institutionalised practices covered all stages of same-sex loving, from courting to coupledom to sex. Athenian same-sex courting meant literally following a boy around or writing "so-and-so is beautiful" in a public place. Thousands of examples of such "kalos-acclamations" survive, signed by hundreds of different hands.

And, in the archaic period at least, there seems to have been an equally formulaic sexual practice when one's wooing got a result - "Athenian homosex", what they called diamerion, or "between-the-thighs" sex, ie "frottage". Spartan homosex, on the other hand, meant sex with one's cloak on: "everything except the dirty deed itself": a fragment from a vase shows the great Spartan hero Hyacinthus engaged in precisely this bizarre sexual act with his lover the winged wind-god Zephyr, hovering with him above the horizon. Was this what our well-informed source was alluding to when he claimed that the Spartan "lawgiver laid down that it was shameful to be seen to reach out to touch the body of a boy"? Doubtless there was a great deal of same-sex loving on Crete, fumblings, fondnesses and passionately devoted relationships, that did not involve a tug-of-war, two months of hunting and the sacrifice of an ox. So we need to make a further distinction between "Cretan homo-sexuality"in all its customary, disruptive and expensive glory, which may have occurred only once or twice a month, and "homosexuality in Crete", the latter, by its very undisruptive and unspectacular nature, much more frequent, but also much more elusive and certainly very difficult now to reconstruct.

Another important principle was to recognise that the same words can be used to mean different things. This is especially important when we come to the question of age. Often "boy" (pais) refers specifically to the formal age-grade of Boys, ie those who have not yet been certified as 18, following two physical examinations, performed first by their local parish and then by the Council of Athens. Those who failed this examination were sent "back to Boys", and the council fined the parish that had allowed his candidature to go ahead. In Athens these under-18s were vigorously protected, rather like the young women in a Jane Austen novel, although their younger sisters would have been expected to be married by the age of 15. These were the Boys who were escorted to the gymnasium by the slave paidagogoi and followed around at a distance by a pack of admirers. "A guard of his honour" is how one source describes it, trying to explain the contradictory custom.

Only those in the age-grade above, "18" and "19", a group usually referred to as Striplings (meirakia) or Cadets (neaniskoi), were allowed to exercise alongside them. But even they were forbidden from "mixing" with the Boys or even from "conversing" with them. A number of ancient sources testified to the existence of such strictures, but it was nice nevertheless when, in 1949, an inscription from a Macedonian gymnasium confirmed them: "Concerning the Boys: none of the Cadets may enter among the Boys, nor chat to the Boys, otherwise the gymnasiarch shall fine and prevent anyone who does any of these things." These rules were only relaxed during the festival of Hermes - a kind of holy sports day, it would seem.

So far so consistent. The problem is that the sources can also use this same term "boy" more informally, to refer to the next age-grade up, ie that of the Striplings and Cadets, the under-20s, who were not so well-protected. Indeed, suddenly released from the watchful gaze of their chaperones, empowered by citizenship and a long-awaited inheritance from their often long-dead fathers (Greek men were middle-aged when they married their teen-brides), but still immune from the obligation to fight wars in foreign parts, these Striplings seem to have made the most of their new-found autonomy. They seduced married women of their own age while their husbands were away fighting battles or on business trips, squandered money on dice or fast horses or on courtesans with expensive tastes, or, indeed, finally said "oh, alright then" to one of the pack of persistent erastai

Often the sources make it clear that the "boys" they are referring to are in fact 18 or over: "There was this boy or rather a sweet little Stripling, and this boy had lots of admirers . . ."; "Cleonymus, of the age-grade just out of Boys . . .", "Agathon a somewhat recent Stripling . . ." But they don't always take such precautions, and we have to read carefully to clarify which kind of "boy" they are talking about.

But sometimes images revealed a different picture, ie they showed under-18s in the gymnasium being sexually abused not only by Cadets but even, very occasionally, by mature men. There are only a handful of such images, produced in the decades around 480BC, but they have been endlessly reproduced in books so that they seem rather more plentiful. Some have thought such images must indicate yet another about-turn in sexual attitudes. But the abused Boys start to appear at exactly the same time that we start to see the first images of the slave-chaperones whose job it was to protect them. There is a more economical solution to this particular contradiction, for these images are showing precisely what the laws proscribed, ie they are reflections not of reality but of anxiety.

Finally of course we need to acknowledge that our sources are not there for our benefit, to tell us what was going on, like radio commentators at a social gathering, but that we are eavesdropping on a debate about what Greek homosexuality was and what it should be. This debate seems to have become particularly intense in the 4th century, and the vast majority of our information about it comes from three men, writing in the decades around 350 BC, and almost certainly acquaintances: Plato, Xenophon and Aeschines. It seems clear that what provoked so much debate at this time was the development of a flourishing market for handsome boys, slaves, male prostitutes and the cithara-boys, who sang to the lyre and danced at parties. It was this challenge that our authors were responding to, wondering what the difference was in the end between the love-smitten guests at a dignified symposium and the cithara-boy hired to entertain them, between a politician who had had many admirers and a common whore. Athenian homosexuality, with all its highly patterned practices, was suddenly threatened with a highly visible doppelganger, which replaced the discourse of "admirers", "beloveds" and "gracious favouring" with a world of clients, contracts, prices and tricks. Greek Love was confronted for the first time with a rather too vivid image of sheer homosexual lust.

The sex-market had one other consequence. It made it clearer that some men were rather more devoted to handsome boys than others, going well beyond the call of duty, prepared to spend large amounts of money on them and indeed to get into fights over male slaves, while remaining immune to the charms of courtesans - men like Misgolas "always surrounded by cithara-boys, devoted to this thing like one possessed", or Ariaeus "always accompanied by handsome Striplings". A new type of person was beginning to emerge - the homosexual himself.

· The Greeks and Greek Love by James Davidson is published by Weidenfeld and Nicolson on November 29