The records of Madrid before the tenth century are extremely scanty, and the early history of the city is largely conjectural. There is no doubt that the Moors established a fortress here, and called it Majrît; but the Romans were in possession before the Arab conquest of the Peninsula, as certain tablets, discovered in the city by Fernandez de Oviedo, serve to prove.
Upon the disruption of the Khalifate the town became subject to Toledo. Whether it was reconquered before or after the fall of that city, by Alfonso VI., is a vexed question. The credit of taking the town is assumed by the people of Segovia. At this time (1085) Madrid was encompassed by a strong wall, stretching from the Moorish Alcázar, now the Royal Palace, to the Church of our Lady of the Almudena; thence to the street of Segovia by the Cuesta de los Ciegos to the Puerta de Moros, and through the Calle Mayor and the Plaza de Oriente to the Alcázar.
According to an old tradition, still accepted by a part of the populace of Madrid, an image of the Virgin of the Almudena, now in the possession of the nuns of the Sacramento Convent, was concealed by the zealous Christians, during the Moorish occupation, in a tower of the city wall. Three hundred years after the sacred image was discovered and restored to the Church. There is a similar legend concerning the sculpture of the Holy Mother found at about the same date.
Upon the victory of Alfonso, the mosque was purified and dedicated to the Vírgen de la Almudena, and on the site is the fine new Cathedral. A mixed population of Christians, Jews, and Moors lived within the city walls at this period, and the staple industries were the making of hemp, linen, and cloth. One of the regulations of that day referred to the muzzling of dogs, as may be seen from an inspection of the curious Fuero de Madrid, which is preserved by the municipal authorities.
The city is mentioned only occasionally in Castilian annals. Sancho el Bravo in vain sought health and strength from its bracing air.
Under Ferdinand IV. the Cortes first assembled in Madrid, to meet there again in 1335 under Alfonso XI. The townsmen warmly espoused the cause of Peter the Cruel. In 1403, Henry III. sent from the city an embassy to Persia, under Gonzalez Clavijo, to negotiate with the potent warrior sovereign Tamerlane. The emissaries were absent from Spain for two years, and during the journey they visited Constantinople and Samarkand.