History of Madrid "Madrid" evolved from the Mozarabic "Matrit", which is still in the Madrilenian gentilic. The site of modern-day Madrid has been controlled since prehistoric times, and archaeological research found a small Visigothic village nearby. In the mid-9th century, Muhammad I of Córdoba constructed a small castle where the Palacio Real stands today. The Moors built a citadel, al-Mudayna, around this castle. They named the area after the nearby Manzanares River, which the Muslims called al-Majrīṭ (Arabic: "source of water"). From this came the name "Majerit", later spelled "Madrid". The Moors controlled the citadel until Alfonso VI of León and Castile conquered
Madrid be a city with representation in the courts of Castile. In 1202, King Alfonso VIII of Castile gave Madrid its first charter to regulate the municipal council, which was expanded in 1222 by Ferdinand III of Castile. In 1309, the Courts of Castile were joined in Madrid for the first time under Ferdinand IV of Castile, and later in 1329, 1339, 1391, 1393, 1419 and twice in 1435. Since the unification of the kingdoms of Spain under a common Crown, the Courts were convened in Madrid more often. During the revolt of the Comuneros, led by Juan de Padilla, Madrid