Real World Background
According to Geoffrey of Monmouth's History of the Kings of Britain, Stonehenge was raised on its present location by Merlin. During the closing years of the reign of King Vortigern of Britain, Vortigern and his nobles met with Hengist, the leader of the invading Saxons, and his men, on Salisbury Plain to hold a parley. Hengist had plotted treachery, however, and at his signal, his followers drew concealed knives and murdered almost all of the British nobles with them, taking them by surprise. (The only survivors were Vortigern, whom Hengist spared to hold for ransom, and Count Eldol of Gloucester, who fought his way out with a large wooden staff.)
After Aurelius Ambrosius (Uther Pendragon's older brother and King Arthur's uncle) had replaced Vortigern on the throne of Britain and defeated the Saxons, he wished to raise a monument to the slaughtered British nobles and sent for Merlin to seek his advice. Merlin counselled him to go to Ireland and remove a ring of stones from Mount Killaurus, placed there by a race of giants long ago. Aurelius at first dismissed the idea, but Merlin assured him that the stones were worth the trouble of taking them, and even possessed healing properties. Aurelius at last agreed to the wizard's advice, and sent his younger brother Uther to Ireland with an army, and Merlin as well, to claim the stones. After defeating the Irish king Gilloman in battle, Uther and his men tried to move the stones but were unable to do so. Merlin announced that he would take over, and transported the stones easily to the Britons' ships. (Geoffrey describes Merlin's act as apparently accomplished more through fine engineering skills than magic, but later versions of the story reimagine it as magic - some accounts even have Merlin compelling the Devil to carry the stones to Britain.) Once they returned to Salisbury Plain, Merlin set them up again in their current location. When both Aurelius and, later on, Uther Pendragon died, they were buried within Stonehenge. (Arthur was not, thanks to his being taken away to Avalon, but his successor, Constantine of Cornwall, was also laid to rest there when he died.)
In fact, Stonehenge was raised on Salisbury Plain long before Merlin's lifetime. The first version of it, dating to around 3000 B.C., was only an earthen mound with a ditch surrounding it, and wooden structures which have long since vanished. Later on, around 2600 B.C., a set of bluestones were added to this (the bluestones are thought to have been quarried in the hills of southern Wales; some scholars believe that the legend of Merlin transporting Stonehenge from Ireland is a confused memory of this event), and still later on, the larger stones, known as sarsens, were added around 2100 B.C. The exact purpose of Stonehenge is unknown, though there have been many theories, such as a place of worship or (a theory suggested by Dr. Gerald Hawkins, but not accepted by all scientists) an early astronomical observatory.
Stonehenge was often called "the Giants' Dance" in legend, and an alternate myth about its origins claims that the stones were once a race of giants, turned to stone for dancing on Sunday.