The memory of Babylon is like the remains of a ziggurat. Hidden below ground level lay almost all the millennia of the Mesopotamian empires, a gigantic span of human history almost totally forgotten and unknown until the excavations of the 19th century. Projecting above the sands was only the tip, the last seven or eight centuries BC when the Assyrian and late Babylonian empires towered over the Middle East. But this tip was visible across the ancient and medieval worlds, its bulk overgrown with the thickets of fantastic myths, the tales of great religions and the origin-stories of peoples, its sides riddled with caves in which lived monsters of the human imagination.

This ground level is the spread of writing, the moment at which travellers and chroniclers began to record their Babylons. The Bible's Old Testament, above all, transmits a mass of legend and history from the reigns of Nebuchadnezzar and his successors, a period witnessed by the Jews of the 'Babylonian Exile' after the great king sacked Jerusalem in 597 and 587BC and deported its elite to Babylon. Herodotus wrote about Babylon, as did many other Greeks; the Koran described it, and so did Arab travellers and medieval rabbis. The Greeks were the first to mention the Hanging Gardens (still unidentified, if they ever existed). But the Bible remained the main source for some of the most powerful images: the Tower of Babel; the ordeals of Daniel; the madness of Nebuchadnezzar reduced to a naked, crawling creature eating grass; Belshazzar's Feast and the writing on the wall; the Whore of Babylon and the sinful city's cataclysmic destruction.

The show in Bloomsbury is the last of three European exhibitions, in which the Louvre, the Pergamon Museum in Berlin and the British Museum shared their treasures. The first two covered the whole span of ancient Mesopotamian history. But the British Museum, boldly and brilliantly, decided to concentrate on that 'exposed tip', on Nebuchadnezzar's late Babylon, whose memory contributed so much to the imagery and fantasy of the whole Eurasian world, Christian, Muslim and Judaic. The result is an exhibition in which archaeology dances expertly with myth. The reality of that Babylon (the material evidence revealed by excavation and above all the political and spiritual culture which emerged as scholars learned to read the cuneiform script) is confronted in every room with the other reality - the wild things that human imagination did to Babylon in the next two and a half millennia.

The material bits are stunning enough. The Germans carried out the main exploration of the site in the late 19th and early 20th centuries, and the Berlin museums - whose vast halls contain the reconstructed Ishtar Gate and part of the Processional Way - have lent whole panels of glazed blue and gold tile on which bulls, lions and the famous 'Mushussu' dragons stride around the visitors. From the old German archaeologists, Robert Koldewey and his team of artists and surveyors, come magnificent paintings of how the Ishtar Gate quarter must have looked, and models of the whole city straddling the Euphrates. The British Museum contributes many of the spectacular cuneiform inscriptions. Here is the 'East India House' slab, which is Nebuchadnezzar's own commemoration, in great detail, of his majestic rebuilding of the city's sacred districts, the Babylonian 'world map' on baked clay, and the tablet describing the creation of the world by the supreme god Marduk. The 'Cyrus Cylinder', inserted into the base of a ziggurat after the Persian conquest in 539BC, is a piece of Persian propaganda explaining (in terms Messrs Putin and Medvedev might use today) why King Cyrus was obliged to invade Babylon in order to protect the human rights of its inhabitants. Another tablet (this one from Berlin) records the generous oil rations allotted to Jehoiachin, the captive king of Judah, and nicely confirms parts of the same story in the Second Book of Kings.

The first wave of archaeologists, like many of the travellers before them, were preoccupied with verifying the biblical and classical accounts. This often skewed their vision; they tended to find what they were looking for. The Germans wrongly thought that they had found the Hanging Gardens of Babylon. Enormous efforts went into seeking the Tower of Babel, which has now been safely identified in the colossal foundations of the Etemenanki ziggurat, dedicated to Marduk.

Here, the exhibition's interlace of fact and legend comes triumphantly into play. There are clay tablets recording the building of the ziggurat by Babylonian kings, together with its measurements (it was nearly as high as St Paul's) and a superb Berlin model reconstruction. But then come the dreams and visions - paintings of the Tower beginning with 15th-century manuscripts and continuing through Pieter Bruegel the Elder and Maarten van Heemskerck, down to haunting versions by MC Escher (1928) or Michael Lassel's melancholy tower of shoes and family photographs. Julee Holcombe's Babel Revisited (2004) makes the Tower look like downtown Houston, Texas, but in a state of perpetual demolition and construction.

There is no question about it: the Old Testament has won the myth battle over Babylon. For 2,000 years, Babylon has meant vanity, idolatry, monstrous luxury and vice, the hubris not only of great kings but of the whole human species as it reaches upwards for the stars. Every doom-merchant, from Jeremiah down to the Rastafarians, has enjoyed taking a kick.

And yet so much of the myth is nonsense. Jeremiah became a pampered Babylonian collaborator after the fall of Jerusalem, while the deported Jews ('by the rivers of Babylon we sat down and wept') were respected as a talented elite; many of them stayed in Mesopotamia until modern Iraq drove them out. Babylonian science contributed the basics of astronomy and mathematics, and the division of time into sixtieths. Semiramis, the queen supposed to have built Babylon and beheaded all her one-night-stand lovers, was really an Assyrian queen called Sammu-Ramat who had nothing to do with the place. The city was not destroyed for its sins, but faded slowly into insignificance.

This exhibition ends with modern barbarities: Saddam Hussein's cult of himself as the new Nebuchadnezzar, and the damage done to Babylon since 2003 by American and Polish troops based among the ruins. Babylon: Myth and Reality is the third in a series of grand British Museum shows about departed emperors and empires. Shi Huangdi's China, Hadrian's Rome and Nebuchadnezzar's Babylon will be followed by Shah Abbas in 17th-century Persia. If only this 'Ozymandias' programme ('look on my works, ye mighty, and despair') could run on to the recent empires of Napoleon, Hitler and Stalin, including Queen Victoria's, we would learn even more about how legend grows over the giant rubbish dumps of history.