Afonso was the son of Teresa of León and Henry of Burgundy, rulers of the County of Portugal. Henry died in 1112, leaving Theresa to rule alone. Unhappy with Theresa's romantic relationship with Galician Fernando Pérez de Traba and his political influence, the Portuguese nobility rallied around Afonso, who revolted and defeated his mother at the Battle of São Mamede in 1128 and became Count of Portugal soon afterwards. In 1139, Afonso renounced the suzerainty of the Kingdom of León and established the independent Kingdom of Portugal.