El Cid was killed in July 1099 while defending the city from an Almoravid siege, whereupon his wife Ximena Díaz ruled in his place for two years