Charlemagne was not really defeated in his lifetime but once. It was not far from here, exactly 1230 years ago (except for the Gregorian calendar correction of 10 days).
The evening of August 15th of the year 778, after a failed attempt to capture Zaragoza from the Moors and after a pretty much annoying decission of demolishing the walls of Pamplona, the capital of the unruly southern Basques, the rearguard of his army was ambushed and annihilated at the Pyrenean passes. The best knights of the Frankish Empire were killed on the spot, these were not only famous Roland, Margrave of Brittany and cousin of Charlemagne, but also such important ministers as Anselmus, Mayor of the Imperial Palace, and Eghinard, Count Palatine. When Charlemagne with the main army could return the day after found only corpses and vultures feeding on them.
This battle is known to the world as the Battle of Roncevaux (or Roncesvalles in Spanish), meaning "Roland's Valley", but to the Basques the placename is recalled as Orreaga. It probably was not in the commemorative spot of later date at Ibaineta but somewhere east of it, as the ancient Roman road, still in use in the 19th century, did not follow the modern road but flatter, yet narrower, passages through the Pyrenean summits, perfect for such a guerrilla attack.
History manual's depiction of Charlemagne founding is cousin's corpse
Why did the Basques attack the Franks? Obviously the direct trigger was Charlemagne's decission to destroy the Pamplonese walls, decission that would cause the city to fall to Muslims soon after (though they were eventually expelled by a rebellion). But there were deeper issues: before the Carolingian ascendance and the Muslim invasion, Vasconia, in personal union with the Duchy of Aquitaine, had enjoyed almost a century of de facto independence. It was only the Muslim disruption and the need to seek foreign support what led the Basque-Aquitanian Dukes to accept formal submission to the Franks. Since then the interference of Franks in the internal affairs of Vasconia had became increasingly annoying, naming Frankish Dukes and demoting the national dynasty to mere Earls.
Left: monument erected under Fascism in memory of Roland (notice that Franco means "Frankish"). Right: current state after popular vandalism.
The southern Basques were not even clearly integrated in the Frankish administrative order anyhow. After this first and most famous battle of Roncevaux, there were still other two combats of the same name (and surely in the same strategic place). The second one happened in 812, still in Charles' lifetime, that ended in stalemate due to Frankish precautions. The third and most decissive one was in 824, when the Basques, supported by the Emirate of Tudela (under a Basque dynasty as well) smashed a Frankish army led by the Earl of Auvergne, Eblus, and the Earl of Vasconia and Aragon, Aznar. The latter was spared because of family ties but Eblus was sent to Cordoba where he was beheaded. I speculate that Earl Aznar may have acted as double agent, specially because his brother and successor Seguin arose against the Franks in the North soon after and managed to re-unify northern Vasconia (Gascony and the Northern Basque Country) that was for some time independent again (Viking raids helped anyhow). The result of this third Battle of Roncevaux was the formation of the Kingdom of Pamplona, that would become the main Basque polity for the rest of the Middle Ages.
Locator map. Notice that the actual battle was probably somewhat to the East of the current road.