Afonso was the son of Henry of Burgundy and Teresa, the natural daughter of King Alfonso VI of León and Castile. According to Fernão Lopes' Crónica de Portugal de 1419, the future Portuguese king was born in Guimarães, which was at the time the most important political center of his parents. This was accepted by most Portuguese scholarship until in 1990 Torquato de Sousa Soares proposed Coimbra, the center of the county of Coimbra and another political center of Afonso's progenitors, as his birthplace, which caused outrage in Guimarães and a polemic between this historian and José Hermano Saraiva. Almeida Fernandes later proposed Viseu as the birthplace of Afonso basing himself on the Chronica Gothorum, which states Afonso was born in 1109, a position followed by José Mattoso in his biography of the king. Abel Estefânio has suggested a different date and thesis, proposing 1106 as the birth date and the region of Tierra de Campos or even Sahagún as likely birth places based on the known itineraries of counts Henry and Teresa.
Henry and Teresa reigned jointly as count and countess of Portugal until his death on 22 May 1112 during the siege of Astorga, after which Teresa ruled Portugal alone. She would proclaim herself queen (a claim recognised by Pope Paschal II in 1116) but was captured and forced to reaffirm her vassalage to her half-sister,
Urraca of Léon.
It is not known who was the tutor of Afonso. Later traditions, probably started with João Soares Coelho (a bastard descendant of Egas Moniz through a female line) in the mid-13th century and ampliated by later chronicles such as the Crónica de Portugal de 1419, asserted he had been Egas Moniz de Ribadouro, possibly with the help of oral memories that associated the tutor to the house of Ribadouro. Yet, contemporary documents, namely from the chancery of Afonso in his early years as count of Portucale, indicate according to José Mattoso that the most likely tutor of Afonso Henriques was Egas Moniz's oldest brother,
Ermígio Moniz, who, besides being the senior brother within the family of Ribadouro, became the "dapifer" and "majordomus" of Afonso I from 1128 until his death in 1135, which indicates his closer proximity to the prince.
In an effort to pursue a larger share in the Leonese inheritance, his mother Teresa joined forces with Fernando Pérez de Trava, the most powerful count in Galicia. The Portuguese nobility disliked the alliance between Galicia and Portugal and rallied around Afonso. The Archbishop of Braga was also concerned with the dominance of Galicia, apprehensive of the ecclesiastical pretensions of his new rival the Galician Archbishop of Santiago de Compostela, Diego Gelmírez, who had claimed an alleged discovery of relics of Saint James in his town, as a way to gain power and riches over the other cathedrals in the Iberian Peninsula. In 1122, Afonso turned fourteen, the adult age in the 12th century. In symmetry with his cousin he made himself a knight on his own account in the Cathedral of Zamora in 1125, with the permission of his mother. After the military campaign of Alfonso VII against his mother in 1127, Afonso revolted against her and proceeded to take control of the county from its queen.