Álvar Fáñez (or Háñez) (died 1114) was a Leonese nobleman and military leader under Alfonso VI of León and Castile, becoming the nearly independent ruler of Toledo under Queen Urraca. He became the subject of legend, being transformed by the Poema de Mio Cid, Spain's national epic, into Álvar Fáñez Minaya, a loyal vassal and commander under Rodrigo Diaz de Vivar, El Cid, during the latter's exile and his conquest of Valencia. Family Álvar derived from the same Castilian noble stock that produced El Cid and is called his "sobrinus" (nephew or more general younger male kinsman) in a contemporary document. He married Mayor Pérez, a daughter of count Pedro Ansúrez of the powerful Beni Gómez clan, and had by her (it would seem) two daughters: Eilo who married successively counts Rodrigo Fernández de Castro and then in 1146/8, as his third wife, Ramiro Fróilaz; and Urraca, who married count Rodrigo Vélaz. Courtier and General Álvar was at the royal court at least from 1076 (the last time he and El Cid appear together). In 1086, Alfonso sent Álvar to Valencia in order to place his candidate, al-Qadir, on the throne. This was accomplished with ease, although Fáñez would have to return when al-Qadir was besieged months later. Alfonso recalled Álvar's troops later that year to take part in what would be a defeat at the Battle of Sagrajas. In 1091, he led a relief force that was defeated at Almodóvar. By the mid-1090s, he had been placed in an essentially independent command of the eastern defenses of the Kingdom of Toledo, spanning from his father-in-law's military command at the city itself to that of his kinsman El Cid at Valencia. He also began to appear more frequently in royal documents. In 1097, he joined Alfonso's army on the campaign that was to lead to a pair of defeats, of the main army under Alfonso near Consuegra, and of a flanking army under Fáñez in the Cuenca district. Two years later, he appears as Alcalde of Toledo. He was present in 1108 at the disastrous Battle of Uclés, escaping with a group of horsemen from an envelopment that claimed most of the Castilian army. Seven less fortunate counts and over a thousand men were killed or captured and beheaded, with the infante Sancho, the heir to the throne, being killed while trying to escape. Álvar fled north to organize the