On the afternoon of August 15, 778, the rear guard of Charlemagne's army was massacred at Roncesvals, in the mountains between France and Spain. Einhard, Charlemagne's contemporary biographer, sets forth the incident as follows in his Life of Charlemagne:

While the war with the Saxons was being fought incessantly and almost continuously, [Charlemagne] stationed garrisons at suitable places along the frontier and attacked Spain with the largest military force he could muster; he crossed the Pyrenees, accepted the surrender of all the towns and fortresses he attacked, and returned with his army safe and sound, except that he experienced a minor setback caused by Gascon treachery on returning through the passes of the Pyrenees. For while his army was stretched out in a long column, as the terrain and the narrow defiles dictated, the Gascons set an ambush above them on the mountaintops—an ideal spot for an ambush, due to the dense woods throughout the area—and rushing down into the valley, fell upon the end of the baggage train and the rear guard who served as protection for those in advance, and in the ensuing battle killed them to the last man, then seized the baggage, and under the cover of night, which was already falling, dispersed as quickly as possible. The Gascons were aided in this feat by the lightness of their armor and by the lay of the land where the action took place, whereas the Franks were hindered greatly by their heavy armor and the terrain. In this battle Eggihard, the surveyor of the royal table; Anselm, the count of the palace; and Roland, prefect of the Breton Marches, were killed, together with many others. Nor could revenge be taken at the moment, for as soon as the act had been done, the enemy scattered so completely that no trace of them was left behind.

To make sense of his excursions into Spain, we must know that Charlemagne (742?-814), king of the Franks, was a committed, militant Christian. A loyal ally of the pope and a great conqueror, he forced conversions as he expanded the boundaries of his empire outward from his central territory, straddling present-day France and Germany. In 800 he was crowned emperor by the pope, legitimizing his rule over the former Roman empire in western Europe. While Spain was at this time an extremely prosperous, even splendid, Muslim state, European Christianity was rather fragile. Many of the tribes of Europe were pagan, Islam was expanding with phenomenal rapidity, and Spain in particular, at the southern borders of Charlemagne's land, represented just how precarious was Christianity's hold. In 778 Charlemagne invaded Spain, trying to take advantage of skirmishes between the Muslim rulers, but was repulsed at Saragossa. Later on, in 801, decades after the disaster at Roncesvals, vassals of Charlemagne were able to capture Barcelona and establish a frontier just beyond the Pyrenees. They never, however, got more than this slender foothold on the peninsula. (For more information, see the section on Charlemagne in the Early Middle Ages SparkNote.)

In the reliable chronicles, Roland and the Roncesvals massacre get only a brief mention. Perhaps, as some have suggested, the massacre really was a very bad blow to Charlemagne's empire, instead of the "minor setback" described by Einhard, and perhaps Roland was in fact much more than an ordinary "prefect of the Breton Marches"; perhaps, as Charlemagne's official historian, Einhard was trying to make an embarrassing defeat and a painful loss sound less grave than they were. We do not know. In any case, the story told in The Song of Roland has some connection to the history of Charlemagne's failed conquest of Spain in 778, but this connection is rather loose. Most of the story is doubtless just a story, without historical basis. The Song of Roland is not a history book, but an epic poem which takes all sorts of liberties, making vivid heroes out of dusty names, making adversaries into the most revolting of villains, and throwing on all alike an air of grandeur. It does not give us facts—any quick comparison shows that it contradicts the records of history in a thousand places—but instead legend.

While this epic isn't history in the same way that even Einhard's very biased chronicle, for instance, is, it uses history to great effect. We cannot say for certain who wrote The Song of Roland, or when, or where, but evidence suggests that it was composed around the beginning of the twelfth century, centuries after Charlemagne's reign. This was the time of the First Crusade against the Muslims in the Holy Land, directly inspired by Pope Urban II's famous speech at the Council of Clermont in 1095. Urban exhorted all Christendom to fight for the Sepulcher, promising that such war was holy and that fighting in it counted as full penance. It is probable that the Song of Roland was written after this speech, for before this Turpin's militant theology would likely have been considered heretical. The Song of Roland, born during this time, serves the Crusades as a powerful piece of propaganda. It must be remembered that political and ideological motivations do not affect a poem's stature as a poem; The Song of Roland is certainly propaganda, but it does not therefore follow that it is "mere propaganda." Most works of art contain ideological or political elements, or at least make ideological or political assumptions; what ultimately distinguishes "mere propoganda" from real art is not political content, but aesthetic success. And by that standard, The Song of Roland deserves its place in the canon of medieval literature.

By the time that the The Song of Roland was written, more than three centuries after the events it recounts, Charlemagne had become a superhuman figure in the European imagination and a hero of romance; the stories of his exploits assumed the proportions of the fantastic. He provides an ideal base on which to build enthusiasm for the Crusades. While no one thought of going on a Crusade until centuries after his death, his figure as both a man of God, beatified and in some churches honored as a saint—he was thought to have been in communication with the angels and the direct instrument of God's will on earth—and as fierce a warrior as any made his image an excellent symbol for the spirit of the Crusades. The bits of history that find their way into the The Song of Roland are remolded to fit the crusaders' world-view. The massacre at Roncesvals becomes much more than a mishap; it becomes a drama of good and evil, a demonstration of the wickedness of betraying the Christian cause. While in Einhard's chronicle, the Frankish soldiers are ambushed by Gascons, a group of Christians hostile to Charles's empire, in The Song of Roland, they are ambushed by Saracens, the medieval European term for Arabs, and, by extension, all Muslims. This helps the crusaders of the twelfth century all the more easily see the situation of the Franks in The Song of Roland as applicable to their own. Charlemagne's conquest of Spain becomes a model for their own conquest of the Middle East. Roland, Turpin, and Olivier become their own glorious forefathers, demonstrating the ideal of the holy warrior, who serves God and his king with the same fierce loyalty; the portrayal of the Saracens, on the other hand, demonstrates the blatant evil of the Muslims, the enemy they will meet and fight in the Middle East. The final product of the epic poem has everything to do with the needs of the twelfth century and very little to do with the events of the eighth century; however, one of the needs of the men of the twelfth century was to find a heroic model for their own mission in the past.