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.