even Seville. The Caliphate of Córdoba was gaining power, and began to attack Leon. King Ordoño allied with Navarre against Abd-al-Rahman, but they were defeated in Valdejunquera in 920. For the next 80 years, the Kingdom of León suffered civil wars, Moorish attack, internal intrigues and assassinations, and the partial independence of Galicia and Castile, thus delaying the reconquest and weakening the Christian forces. It was not until the following century that the Christians started to see their conquests as part of a long-term effort to restore the unity of the Visigothic kingdom. The only point during this period when the situation became hopeful for Leon was the reign of Ramiro II. King Ramiro, in alliance with Fernán González of Castile and his retinue of caballeros villanos, defeated the Caliph in Simancas in 939. After this battle, when the Caliph barely escaped with his guard and the rest of the army was destroyed, King Ramiro obtained 12 years of peace, but he had to give González the independence of Castile as payment for his help in the battle. After this defeat, Moorish attacks abated until Almanzor began his campaigns. Alfonso V finally regained control over his domains in 1002. Navarre, though attacked by Almanzor, remained intact. The conquest of Leon did not include Galicia which was left to temporary independence after the withdrawal of the Leonese king. Galicia was conquered soon after (by Ferdinand, son of Sancho the Great, around 1038). However, this brief period of independence meant that Galicia remained a kingdom and fief of Leon, which is the reason it is part of Spain and not Portugal. Subsequent kings titled themselves kings of Galicia and Leon, instead of merely king of Leon as the two were united personally and not in union. Kingdom of Castile (1037–1230) Ferdinand I of Leon was the leading king of the mid-11th century. He conquered Coimbra and attacked the taifa kingdoms, often demanding the tributes known as parias. Ferdinand's strategy was to continue to demand parias until the taifa was greatly weakened both militarily and financially. He also repopulated the Borders with numerous fueros. Following the Navarrese tradition, on his death in 1064 he divided his kingdom between his sons. His son Sancho II of Castile wanted to reunite the kingdom of his father and attacked his brothers, with a young noble at his side: Rodrigo Díaz, later known as El Cid Campeador.