The nucleus of the Portuguese state was the County of Portugal, established in the 9th century as part of the Reconquista, by Vímara Peres, a vassal of the King of Asturias. The county became part of the Kingdom of León in 1097, and the Counts of Portugal established themselves as rulers of an independent kingdom in the 12th century, following the battle of São Mamede. The kingdom was ruled by the Alfonsine Dynasty until the 1383–85 Crisis, after which the monarchy passed to the House of Aviz.
After the Portuguese Restoration War of 1640–1668, the kingdom passed to the House of Braganza and thereafter to the House of Braganza-Saxe-Coburg and Gotha. From this time, the influence of Portugal declined, but it remained a major power due to its most valuable colony, Brazil. After the independence of Brazil, Portugal sought to establish itself in Africa, but was ultimately forced to yield to the British interests, leading to the collapse of the monarchy in the 5 October 1910 revolution and the establishment of the First Portuguese Republic.
The Kingdom of Portugal finds its origins in the County of Portugal (1093–1139). The Portuguese County was a semi-autonomous county of the Kingdom of León. Independence from León took place in three stages: