County of Portugal

The County of Portugal (; in documents of the period the name used was Portugalia) refers to two successive medieval counties in the region around Braga and Porto, today corresponding to littoral northern Portugal, within which the identity of the Portuguese people formed. The first county existed from the mid-ninth to the mid-eleventh centuries as a vassalage of the Kingdom of Asturias and the Kingdom of Galicia and also part of the Kingdom of León, before being abolished as a result of rebellion. A larger entity under the same name was then reestablished in the late 11th century and subsequently elevated by its count in the mid-12th century into an independent Kingdom of Portugal.
First county.
The history of the county of Portugal is traditionally dated from the "reconquest" of "Portus Cale" (Porto) by Vímara Peres in 868. He was named a count and given control of the frontier region between the Limia and Douro rivers by Alfonso III of Asturias. South of the Douro, another border county would be formed decades later when what would become the County of Coimbra was conquered from the Moors by Hermenegildo Guterres. This moved the frontier away from the southern bounds of the county of Portugal, but it was still subject to repeated campaigns from the Caliphate of Córdoba. The recapture of Coimbra by Almanzor in 987 again placed the County of Portugal on the southern frontier of the Leonese state for most of the rest of the first county's existence. The regions to its south were only again conquered in the reign of Ferdinand I of León and Castile, with Lamego falling in 1057, Viseu in 1058 and finally Coimbra in 1064.
The leaders of the first county of Portugal reached the height of their power in the late 10th century, when Count Gonzalo Menéndez may have used the title "magnus dux portucalensium" ("grand duke of Portugal") and his son Menendo used the title "dux magnus" (grand duke). It could have been this Count Gonzalo who assassinated Sancho I of León after inviting the King to a banquet and offering him a poisoned apple. Not all historians, however, believe that Gonzalo Menéndez was responsible for the king's death and some attribute the regicide to a contemporary count named Gonzalo Muñoz.
In the late 960s Gonzalo's lands were ravaged by Vikings, and in 968, he fell out with king Ramiro III over the latter's refusal to fight the raiders. His son Menendo had close relations with Ramiro's rival and successor, Bermudo II, being made the king's "alférez" and tutor of his son, the future king Alfonso V. Following Alfonso's succession, Menendo would serve as regent for the boy king and married him to one of Menendo's daughters.
The county continued with varying degrees of autonomy within the Kingdom of León and, during brief periods of division, the Kingdom of Galicia until 1071, when Count Nuno Mendes, desiring greater autonomy for Portugal, was defeated and killed in the Battle of Pedroso by King García II of Galicia, who then proclaimed himself the King of Galicia and Portugal, the first time a royal title was used in reference to Portugal. The independent county was abolished, its territories remaining within the crown of Galicia, which was in turn subsumed within the larger kingdoms of García's brothers, Sancho II and Alfonso VI of León and Castile.
Second county.
In 1093, Alfonso VI nominated his son-in-law Raymond of Burgundy as count of Galicia, then including modern Portugal as far south as Coimbra, though Alfonso himself retained the title of "king" over the same territory. However, concern for Raymond's growing power led Alfonso in 1096 to separate Portugal and Coimbra from Galicia and grant them to another son-in-law, Henry of Burgundy, wed to Alfonso VI's illegitimate daughter Theresa. Henry chose Guimarães as the base for this newly formed county, the "Condado Portucalense", known at the time as "Terra Portucalense" or "Província Portucalense," which would last until Portugal achieved its independence, recognized by the Kingdom of León in 1143. Its territory included much of the current Portuguese territory between the Minho River and the Tagus River.
Count Henry continued the "Reconquista" in western Iberia and expanded his county's dominions. He was also involved in several intrigues inside the Leonese court together with his cousin Raymond and sister-in-law Urraca of Castile, in which he supported Raymond's ascension in return for promises of autonomy or independence for Portugal. In 1111 the Muslims conquered Santarém. When Count Henry died in 1112, the population of the County of Portugal, including the powerful families, favored independence. Henry's widow, Theresa, took the reins on behalf of her young son, and allied herself with Galician nobility in order to challenge her sister queen Urraca's dominance and briefly used the title Queen. However, she was defeated by Urraca in 1121 and forced to accept a position of feudal subservience to the Leonese state. Her own son, Afonso Henriques, took the reins of the government in 1128 after routing his mother's forces in the Battle of São Mamede, near Guimarães. After this battle, he began to exhibit a seal with a cross and the word "Portugal", and he continued to win battles, supported by the nobles of Entre-Douro-e-Minho. Nevertheless:
It was his triumph in the Battle of Ourique in 1139, which led to his proclamation as King of Portugal by his troops. Finally in 1143, his nominal overlord Alfonso VII of León and Castile recognized the "de facto" independence of Portugal in the Treaty of Zamora.