The Kingdom of Asturias was formed after Pelayo defeated Muslim troops in the Battle of Covadonga in 722, establishing the first Christian kingdom in Iberia. Alfonso I was elected King and expanded the Kingdom with Oviedo as its capital. Over subsequent kings like Alfonso II and III, the Kingdom grew northward into Portugal and westward along the Duero and Ebro valleys. By 924 under later kings, it occupied the entire northwest of Iberia and the capital was moved to Leon, with a line of castles built along the border for defense against Muslim incursions.