There is something so obvious, so crude, about Leonardo da Vinci's portrait of Cecilia Gallerani that it might seem beneath discussion. The 16-year-old mistress of the ruler of Milan, Ludovico Sforza, is stroking an ermine. The creature is white, furry and bony. Scholars have written reams about this ermine's significance as an allegory of purity. To my mind, with its long snout and serpentine body, her pet looks unmistakably phallic – and her control of it suggests that Sforza has been tamed by his young mistress.

Leonardo's Cecilia has sloping, slender shoulders, white skin over delicate collarbones, a pale throat adorned with a black necklace, an exquisitely elongated face with a superb nose. She is turning to look at someone, perhaps at Sforza himself. This sidewards turn gives the artist an unselfconscious view of her, and in it one senses the depth of Leonardo's fascination. It is not just Sforza who adores Cecilia. From this portrait, it looks as if the painter would like to sleep with her, too.

This sensational study will be the wonder of wonders at the National Gallery's Leonardo exhibition, which opens next month. Its arrival from Krakow, where the violence and divisions of 20th-century history have made it more or less invisible for many years – and so skewed the oeuvre of the world's greatest artist – will introduce us to another Leonardo da Vinci: the man who loved women.

The idea that Leonardo could be aroused by a woman at all is a bit of a surprise. This is not the image of him that has come down to us. Ever since Renaissance witnesses recorded that he loved to surround himself with beautiful young men, his homosexuality has been an open secret. As a youth, he was twice accused of sodomy, though never prosecuted (apparently because the young men who were charged with him came from powerful and wealthy families). Yet Leonardo, as Vasari's account of his life and the artist's own notebooks confirm, went on to live openly with a household of youths led by Salai, his handsome, thieving apprentice – to whom he eventually left the Mona Lisa.

In 1910, Sigmund Freud published a revolutionary psychoanalytic study in which he argued that Leonardo was homosexual but celibate, and that he sublimated his erotic side into endless research. Freud pointed to a coldly clinical drawing of heterosexual intercourse among Leonardo's notes, which shows the lovers standing up, like mannequins. It is conversely true that Leonardo drew many highly detailed studies of the anal sphincter. When he died, he left some works to Salai, while his more recent companion Francesco Melzi inherited his notebooks.

This view of Leonardo is essentially true, but it does leave something out. All his life, the painter was passionately involved with women – on canvas, at least. It was not just that Leonardo liked to portray women (of his five surviving portraits, four are of women; the fifth is of a young musician). It has to do with the way he chose to depict women, the way he showed them to be fully rounded human beings. While earlier Renaissance artists had sculpted and painted profoundly characterful portraits of men (look at Mino da Fiesole's rugged bust of Diotisalvi Neroni), when they turned their attention to women, they seemed obsessed only with exterior beauty. In Antonio del Pollaiuolo's portrait of an unknown woman, done in about 1475 and now hanging in the Uffizi, the model stands in profile. We cannot see her eyes, or guess at what she's thinking. Leonardo's teacher, Andrea del Verrocchio, made a marble bust of a nameless young woman, a truly great Florentine work (now in the Bargello museum in Florence), but her eyes are blank, her mind apparently absent.

Even while he was fighting off sodomy accusations in Florence, the 26-year-old Leonardo da Vinci painted a picture of a young woman that blew apart the patriarchal conventions of his native city. His Ginevra de' Benci turns to face us, her serious eyes meeting the beholder directly. She was the daughter of a wealthy Florentine family, but Leonardo dressed her in plain clothes in order to focus on her face; in a motto painted on the back of the wooden panel, he declared that she was not just good-looking but had "virtue". Framed by a spiky bush of juniper (Ginevra means juniper), her young, coolly assertive face seems – when you see this painting in the National Gallery of Art in Washington, DC – to expand to fill your mind. It is not just her refined yet adolescent features, but the power of her eyes, shining with gravity; like the eyes in any Rembrandt self-portrait, they really do seem windows to the soul.

Leonardo moved to Milan near the start of the 1480s, and began working for Sforza, as an engineer, sculptor and painter. He portrayed the ladies of the court with the same sense of inner character he brought to Ginevra de' Benci. His subject La Belle Ferronnière (perhaps another of Sforza's mistresses) looks over a parapet, her gaze mysterious. Isabella d'Este, who ruled Mantua in northern Italy, actively sought out Leonardo to paint her portrait, too. Italy's handful of wealthy, independent women were fans and would-be patrons. Isabella wrote to Cecilia Gallerani, Leonardo's most spectacular model, asking if she could borrow the portrait of her so that she could get an idea of his work. Cecilia obliged, although she warned Isabella that she had aged over the intervening decade and no longer looked like that. She must have been truly beautiful at 16, if she ever did look quite like that.

Leonardo's portraits are flirtatious, none more so than the Mona Lisa, the Florentine merchant's wife from whom he elicits such a tantalising smile. But while working on this last of his great portraits to have survived, he also created one of the most provocative female nudes ever painted by a Renaissance artist. Leonardo's Leda is known today only from copies and sketches, but even these show that in the two versions he developed – one crouching, another standing – his nude was intended to inflame.

Earlier Renaissance artists were quite coy with their naked women. Botticelli's Venus adopts a modest pose. But when Leonardo conceived Leda, in about 1504, it was as a nude whose abundantly available body anticipates and resembles the rampantly heterosexual bedroom paintings of Titian and Correggio. Whether crouching among the bulrushes or standing to embrace her swan lover, Leda has a body contoured and posed in a fleshy, sexy way. Soon, in Venice, the young Giorgione would paint overtly amorous nudes that went on to shape the erotica of Renaissance princes; he took his ideas directly from Leonardo, who visited Venice at the start of the century.

The artist had a theory about art and sex. (Of course he did; he was Leonardo – he had a theory about everything.) In his notebooks, he argues that painting is the greatest of all the arts because it can set a picture of your lover before you. A pastoral painting can remind you, in winter, of summer in the country with your beloved. He goes further, into blasphemy. He boasts that he once painted a Madonna so beautiful that the man who bought it was haunted by unseemly thoughts. Even after it was altered, perhaps with the addition of crosses and saintly symbols (as was done in Leonardo's second version of The Virgin of the Rocks), it still gave him an erection when he tried to pray. So in the end he returned the painting to Leonardo, who delighted in this pornographic triumph.

Leonardo's own sexuality appears to transcend gender, to slip into godlike fantasies of androgynous liaisons between worlds. His Virgin of the Rocks includes an angel whose gender it is impossible to determine. No other Renaissance artist was as preoccupied with androgyny: from his earliest works, including an angel he painted in a work by his master Verrocchio, it was Leonardo's trademark. Perhaps in his imagination, he was such an angel, neither masculine nor feminine but both, and able to infuse the world with infinite longing.

We might end with his early painting The Annunciation. A young woman has been surprised in her garden by a winged messenger from paradise. This being looks at her with a hypnotically deep and steady gaze, as if penetrating her with its eyes. Beyond is the open door of a house, and within we glimpse the deep red softness of a bedroom. Is the charge of this religious painting sexual?

Or we could go back to his childhood. Leonardo's memory of early childhood, one that fascinated Freud, was this. He remembered that a bird of prey came down to his crib, inserted its tail feathers in his mouth, and moved them about. Is the beat of those feathers still there in his paintings' unending flutter of desire?