Nobody knew better than him the value of art, the need to preserve the memory of great artists. You feel the emotion, the hushed awe, when he describes seeing pieces of Michelangelo's drawing of the Battle of Cascina in the house of a gentleman in Mantua: "They seem to the eye things divine rather than human." And yet, of all people, it was Giorgio Vasari, author of The Lives of the Painters, Sculptors and Architects (1568), the unrivalled chronicler of the Renaissance, who obliterated every trace of one the most extraordinary projects in Renaissance art.

In the 1560s, Vasari redecorated the Council Hall of the Palazzo Vecchio in Florence, replacing what survived of the most ambitious and tantalising public art commission of the Renaissance. This included two masterpieces that - even as legends, glimpsed through descriptions, copies, a handful of surviving preliminary sketches - have haunted art ever since. At the beginning of the 16th century, in this same room, side by side on the same wall, Leonardo da Vinci and Michelangelo Buonarroti were hired to paint vast battle scenes in direct competition with one another.

One thing can be said for Vasari's replacement paintings: they won't induce Stendhal syndrome, the illness caused by aesthetic excitement that afflicts several visitors to Florence every year. Vasari was a vivid writer but a flat painter. Today the vast walls of the long, rectangular hall are vapid. In a city so rich in beauties, the Council Hall, known today as the Salone dei Cinquecento, isn't even a contender.

So it's a perverse pursuit, in a city with visible masterpieces from Michelangelo's Medici tombs to Brunelleschi's dome, to go looking for what is not there. It feels a little melancholy, standing in the Palazzo Vecchio speculating on what might have been, peering at Vasari's frescos as though we could look through them, when we might be next door in the Uffizi, gorging on Botticellis. But, since the 16th century, people have been obsessed with the lost battle paintings of Michelangelo and Leonardo: artists from Raphael to Rubens; art historians including Kenneth Clark, who called these lost pictures "the turning point of the Renaissance"; the company Editech Art Diagnostics, which is to scan the wall under Vasari's paintings in an attempt to find traces of Leonardo's Battle of Anghiari.

It might sound crass to talk as though the decoration of the Council Hall was a point-scoring competition between two such lofty minds as Leonardo and Michelangelo, but that was how contemporaries saw it. Leonardo was in his early 50s and renowned throughout Europe when he was commissioned in 1503. He had just painted the Mona Lisa. "His fame had so increased," writes Vasari, "that all persons who took delight in art - nay, the whole city of Florence - desired that he should leave them some memorial work."

Leonardo was commissioned to paint a vast wall painting of The Battle of Anghiari, a scene from the 15th-century wars between Florence and Milan. Then, in December 1504, a far younger Florentine was commissioned to paint The Battle of Cascina, which took place between Florence and Pisa in the 14th century, on the same wall of the Council Hall.

Michelangelo was just 29, and a prodigy. Born in 1475 and trained in the sculpture academy created by Lorenzo de'Medici in a garden in Florence, by 1498 he had carved the Pieta in St Peter's in Rome; in May 1504, the same month that Leonardo revised his contract with the Signoria of Florence to put back the completion date of The Battle of Anghiari, Michelangelo's statue of David was installed outside the Palazzo Vecchio. Leonardo, inconceivably, had a rival.

Vasari is explicit that this was a contest. He emphatically says that Michelangelo was commissioned "in competition with Leonardo". With competition came paranoia, hatred. Michelangelo had little time for Leonardo - according to Vasari, he made his dislike so clear that Leonardo left for France to avoid him. For his part, Leonardo made bitchy remarks in his notebooks on the "wooden" qualities of Michelangelo's painting.

So you can't help thinking that Piero Soderini, elected in 1502 as lifetime gonfalonier of justice of the Republic - a little like the Venetian doge - had mischief in his mind when he set Leonardo and Michelangelo to work on the same wall. And, yet, what happened in the Palazzo Vecchio turned out to be more mysterious and more private to both these artists than anyone expected.

There was far more at stake than artistic rivalry. The council hall was the centre of a new, more populist idea of the Florentine Republic, which, after the expulsion of the Medici in 1494, was restored with a far greater commitment than ever before to speaking for the entire city. The rebirth of the Florentine Republic was a moment of intense self-rediscovery for Florence; after a century in which the city had become more like a conventional princedom, it was reasserting republican government. Brilliant minds gave their all to the struggle to recreate the Republic - one of Piero Soderini's close allies was Machiavelli. Historians used to believe, that Machiavelli was instrumental in commissioning Leonardo to decorate the Council Hall.

What is certain is that Leonardo and Michelangelo both had new hope for their city. They had been working far from Florence, in Milan, in Rome. Now they returned. Were they republicans? Michelangelo created the Republic's most seductive work of political art, a powerful symbol of manly, energetic, watchful, clear-eyed heroism: David, hero of the weak against the strong, of Florence against tyrannical powers.

The city of Florence had every reason to expect that Leonardo and Michelangelo, as aware as everyone else of the vulnerability and preciousness of the city's freedom, would create patriotic masterpieces, and that rivalry would spur them on. It spurred them all right - but in odd, hermetic,and pessimistic directions. The images of war they created were not bright and celebratory pageants of chivalry, but enigmatic, disturbing.

Preliminary drawings survive of men and horses by Leonardo; there is a copy, attributed to Rubens, taken from an earlier copy, of the central scene of his painting, known as The Battle of the Standard. For Michelangelo, the main visual source is a painting now in Holkham Hall, Norfolk, by Bastiano da Sangallo, a copy of Michelangelo's Battle of Cascina. Even from these fragments, we can see why contemporaries regarded the Battles of Anghiari and Cascina as the key works of their time - and why they have haunted the representation of war ever since.

Leonardo and Michelangelo, for all their different ages, different styles - Leonardo soft, shadowy, ambiguous; Michelangelo sublimely decisive - and their enmity, had one thing in common. Neither liked to finish anything. By the time Leonardo was commissioned to paint the Council Hall, everyone knew this about him; what no one knew was that Michelangelo - who had been prodigious - was to become dilatory and difficult. In fact, Michelangelo's abortive work on The Battle of Cascina marks the beginning of the pattern of non-completion that was to mark his life. You might even speculate that he learned this from Leonardo.

Leonardo, on this occasion, got a lot further than Michelangelo. He took a long time to finish his cartoon and we know, from sketches of men and horses that survive, how passionately he engaged with it; the horses as tense and confrontational as the men, the men as bestial as the animals - warriors have their mouths snarlingly open, as if they want to bite flesh. Leonardo made a unique machine, a wooden elevator, so he could move up and down the wall in comfort. But, as with the Last Supper, technical ingenuity got the better of him. Leonardo used a method - apparently based on a recipe in the ancient Roman writer Pliny the Elder - to enable him to paint the wall in oils. The mixture didn't work - he may have been cheated on materials; the upper part dried dark and the lower parts disintegrated.

Michelangelo never got past the drawing stage. But what a drawing, everyone agreed. He took over a room in the Hospital of the Dyers in Florence, and drew a full-sized cartoon in superb detail. Everything about it was startling. Leonardo depicted the very heart of battle, an agonising, horrific entanglement of human and animal bodies, but Michelangelo drew war's margins, a moment of bizarre ordinariness, when Florentine soldiers, bathing naked in the Arno, hear the enemy coming and rush to get out of the water and put on armour.

Michelangelo's painting never reached the wall, but Leonardo's did. It's a mystery why it was painted over in 1565, by that same Vasari who wrote Leonardo's life. It was a Leonardo, which meant as much then as now. Vasari reported in 1556 that the Last Supper had deteriorated to "a muddle of blots", but it has been preserved and worshipped ever since in its ruinous state. There is more going on than meets the eye in the Salone dei Quinquecento.

In 1512, a Spanish army sent by the Holy League overthrew the Florentine Republic; Piero Soderini fled and the Medici were returned to power. Machiavelli retired to write his bleak political theory. The sense that Michelangelo was a Republican, despite all he owed the Medici and the Pope as patrons, is strengthened by the way that he again returned to Florence when the Medici were chucked out and the Republic restored one more time in 1527. Michelangelo built defences for this last Florentine Republic; his defences failed, the city fell, the Medici came back in 1530. Michelangelo was forgiven because of his fame.

After 1530, republicanism was finished in Florence, which became a conservative, princely city, whose art would never again be at the forefront of Europe. The Palazzo Vecchio became a Medici palace. When Vasari was commissioned to redecorate the Council Hall, he was suppressing the past, effacing signs of the Republic, of the people. Those signs included Leonardo's Battle of Anghiari.

Today you can walk around Florence seeing ghostly images of the two lost masterpieces. In the Casa Buonarroti is a very early Michelangelo, The Battle of the Centaurs, in which naked bodies twist and wrap around each other and coil and flex as the nude soldiers would have done as they clambered out of the Arno. The most intangible, yet most direct, trace of either battle painting is in the Uffizi, in Leonardo da Vinci's Adoration of the Magi. In the receding distance of Leonardo's unfinished conundrum of a painting are horsemen, engaged in combat. The warriors in Leonardo's battle painting repeated, consciously or unconsciously, those in the earlier Adoration of the Magi. You stand before this astonishing picture, shadowy faces swimming out of the chiaroscuro blur, enigmatic architecture resolving itself out of insubstantial space, and look at those spectral horsemen; they are dream warriors. "Creatures shall be seen on the earth who will always be fighting one with another, with very great losses and frequent deaths on either side," he wrote in one of his prophecies. It is that monstrous version of humanity that Leonardo glimpsed, and painted, in The Battle of Anghiari.

The fascination of the invisible battles of Leonardo and Michelangelo is that they announce a new interiority, emotionalism and self-expression in Renaissance art, of human action no longer making sense, of heroism and martial glory no longer being under control. Just as Machiavelli concluded from the defeat of the Florentine Republic that human affairs are irrational, so the two greatest Renaissance artists created the first modern, disenchanted images of war.

· Palazzo Vecchio, Florence, is open seven days a week. Holkham Hall, Norfolk, is open to the public during the summer months.