Red lips and a rose nipple inflame the cool flesh of Egon Schiele's model as she leans back and, blue eyes looking off to the side, lifts her ruffled skirt to show the artist what he wants to see.

You could not exclude Schiele from an exhibition entitled Seduced: Art and Sex from Antiquity to the Present. Nor could you exclude his Viennese contemporary, Gustav Klimt, whose Reclining Masturbating Girl hangs nearby, nor Picasso, whose painting of himself at the age of about 20 being fellated is in the same room. And yet there's something about that title, "art and sex", that doesn't quite do justice to these artists. It implies that art can sometimes be about things other than sex - and I'm not sure if Schiele or Picasso ever believed it could. I'm not sure if I believe it myself.

This summer, while looking at ice age art in caves in France, I saw breasts and buttocks drawn by some ice age Picasso perhaps 25,000 years ago. People have been making erotica, or pornography, or whatever you want to call it, far longer than the 2,500 years this exhibition surveys. And you have to ask: has art ever been about anything else? As soon as the Greeks invented a lifelike way of depicting the human form, in the sixth century BC, they exploited their discovery to portray sex - as this show illustrates. Who was the beautiful Sapphic red-figure painting of two slender women with triangular breasts and curvy buttocks meant to be enjoyed by?

My one quibble with this show is how misleading it would be to think that sex is somehow a marginalised or hidden theme in art. Just consider the National Gallery, where Bronzino's perverse Venus and Cupid, Titian's mordant Diana and Actaeon, Velázquez's coolly sensual Rokeby Venus, Rembrandt's wonderfully intimate bedroom portrait of Hendrickje Stoffels, and the late works of Degas could all have been included in this show. The theme is potentially limitless, and to isolate "sex" in art might almost have something puritanical about it, a clinical scrupulousness.

But we live in a world that fears erotically charged images. Pornography is loathed even as it is consumed. In Britain, there has been a recent moral panic about one of the artists in this show, Nan Goldin, whose photograph of a naked young girl was removed from an exhibition at Gateshead's Baltic Centre. That is the modern version of anxieties that for centuries drove artists to veil passion in fine ideas. This show includes a copy of Michelangelo's drawing of The Rape of Ganymede, which he gave as a present to a young nobleman he adored, and which portrays Jupiter taking the form of an eagle to carry away a boy he lusted after.

Michelangelo was influenced by the Florentine Neoplatonist Marsilio Ficino when he claimed that when he looked at male beauty it led him up into the pure spiritual realm, beyond lust.

By the 18th century, this doublethink produced the idea of the "nude" as a somehow lustless depiction of the human form. This idea was still so current in the early 20th century that a philospher could claim: "If the nude is so treated that it raises in the spectator ideas or desires appropriate to the material subject, it is false art, and bad morals." To which the art historian Kenneth Clark replied: "No nude, however abstract, should fail to arouse in the spectator some vestige of erotic feeling, even though only the faintest shadow - and if it does not do so it is bad art and false morals." Nowadays, we laugh at the very idea of a sexless nude, but we have got our own anxieties, our own difficulties of definition. Does Goldin pander to paedophiles? Between the old worries and the modern ones, sex is still a dangerous subject. The curators of this brilliant exhibition joyously shove it in your face.

I left with a slide show of erotica from all places and times playing in my head, the wet, raw, slithering photography of Nobuyoshi Araki fading into the proud flesh of Louis XV's mistress, Mademoiselle O'Murphy, lying on her front on a chaise longue in a drawing by François Boucher, giving way to 19th-century photographs in which the models pose identically to what you would see in a modern men's magazine, to Rembrandt's moving engraving of lovers with their clothes on on a chilly night. Aubrey Beardsley's drawing of a gigantic penis and an ancient Roman bronze phallus with bells hanging on it; the detailed, ruffled, silken pink vulva of a white-faced courtesan arching her body over in a Japanese woodblock print and Klimt's woman with her legs apart reaching under her turn-of-the-century skirts to touch herself.

In the rush of images, ideas are generated like the babies who, in Leonardo da Vinci's Leda and the Swan - a copy is shown here of this lost masterpiece - hatch from eggs after Leda's encounter with a god who has taken the form of a giant bird. In Robert Mapplethorpe's X Portfolio photographs, his most controversial works that created legal difficulties for American museums after the conservative Right attacked them at the end of the 1980s, men involved in the S&M scene subject themselves and one another to various constraints and tests: Joe is encased in rubber, Jim has his head sealed in a leather mask, and Mapplethorpe himself poses with a whip inserted in his rectum. Shocked? Disturbed? But walk over to the section that shows a lovely series of 18th-century Chinese scenes in which lovers embrace tenderly in a lotus garden. The mood here is infinitely more delicate and gentle - except the woman wears dainty silken bags over her bound feet.

Sex is not an unchanging natural phenomenon. What does that Roman bronze phallus with bells on it actually mean? And when a woman in a Renaissance picture collects phalluses in a basket, is this about "sex" or witchcraft? Mapplethorpe's photographs are a crucial exhibit because they can be viewed as anthropological documents that record a very specific subculture, the same one, as it happens, that attracted the French philosopher Michel Foucault. "You meet men there who are to you as you are to them," Foucault said of his discovery of the American 1970s gay S&M scene. "Nothing but a body with which combinations and productions of pleasure are possible."

Foucault came to believe that if consenting men in 1970s California could invent a new sexuality from nowhere, sex must therefore be neither an unchanging historical constant nor a primordial drive fighting free of "repression", but something cultures make and unmake. This is the argument of his book The History of Sexuality. In European culture since the rise of Christianity, there is no image of sex from which pain and guilt are wholly excluded - the Christian terror is visibly there in illustrations to 18th-century editions of De Sade. Serious post-classical European art has never produced anything quite like the pure, comment-free eroticism of this show's bright Indian illustrations of lovers demonstrating a series of spectacular positions, or Japan's art of the floating world.

Seventeenth-century Japan saw the rise of a new secular culture in the great cities of Edo (modern Tokyo), Osaka and Kyoto. Religious Noh theatre gave way to kabuki theatre with its everyday scenes, and the cities had pleasure districts whose community of the senses was named after the Buddhist term ukiyo, meaning "floating world". Woodblock prints, with their gorgeous colours, record, or rather invent and mythify, this floating world: lovers are suspended far from workaday worries in their own reality of silk and skin. A man pleasures a woman after they have gorged on oysters; the artist enjoys drawing a visual analogy between oyster and vulva. I cannot think of a European equivalent, and it has to do with what art is in different cultures, as much as what sex is.

European art from the Renaissance into modern times was obsessed with the delineation of reality in space and time. Japanese prints are instead decorative explorations of shape and colour: this makes for a much more tactile art. Male and female genitalia are not "shown" to the spectactor like a provocative fact, as they are by Schiele, in Japanese art; their visible presence is natural and is enjoyed by the artist, who draws comparisons with red frilly garments, or in the case of an erect penis, with a bird's beak.

The same sensibility is at work in Araki's shocking, beautiful images from his series Erotos. In fact, these photographs are the only real contemporary erotica in the show. It is proof of how fraught it is, this looking at sex, that in its closing stages the exhibition chickens out and retreats to a safe definition of high art: so we get Thomas Ruff's blurred, artistic appropriations of internet porn, rather than internet porn. It excludes a whole host of material that would challenge taste and definitions of the pornographic far more provocatively. Why include early porn photographs and exclude fetish photographer Elmer Batters? In graphic art, why exclude sexually obsessed cartoonist Robert Crumb? I suppose they wanted to avoid too many questions about pornography and power - they wanted to create a safe "erotic" space. Yet all the questions a critical viewer might ask are asked by Picasso in his series of etchings of the Renaissance master Raphael in bed with his lover, La Fornarina, "the baker's daughter". It was said that Raphael so adored his mistress - and loved sex - that a patron had to install her in his house in order to get Raphael to finish his frescoes there.

I was at first disappointed to find Picasso - the most sexual artist there ever was - represented only by his youthful painting of a blowjob, although it connects him nicely with Andy Warhol's nearby film (Blowjob), which focuses on an ethereal silvery image of a man's face. Picasso etched Raphael and La Fornarina in 1968, near the end of his life. You wouldn't guess it from the way his line enjoys every detail. Did I say western art has nothing to compare with Japanese sensuality? It does - it has Picasso. And yet, and this is what makes Raphael and La Fornarina the greatest work of art in the show, Picasso knows exactly what he is doing: he knows he is too old to be Raphael any more. In most of the prints, the Pope watches from behind draperies or - hilariously - while squatting on a potty. This is the dilemma of anyone seeing the show: in your imagination are you La Fornarina, or her lover, or the Pope watching on his potty? It's a risky business, admitting to how much you enjoy looking at sex. I loved this show, but left feeling sad and ashamed; then I had to come back the next day and look again. It is the bravest and most intelligent exhibition of the year

· Seduced: Art and Sex from Antiquity to the Present is at the Barbican, London EC2, until January 27. Details: 0845 1207550.