Madrid, originally called Mayrit, was founded by the emir Muhammad at the end of the IX century. It was under the Arab occupation of the Iberian Peninsula, that the city gained importance, since initially the main city in the Spanish plain had been Toledo.
During the Reconquest of Spain by the Christians, Madrid passed from Muslim to Christian hands several times, it was the origin of the mixture of cultures which characterizes the city still today.
The present location of Madrid, in the centre of Spain, was established by the king Alfonso I in 1083. Under Christian control, all symbols of the Muslim world were removed from the city and part of the cultural heritage of Madrid was lost.
During the following centuries the city developed reaching its current aspect. The Main Square (Plaza Mayor) was built under the auspice of John II on the 13th century. Later on, Enrique III ordered the building of El Pardo Palace as a place of residence for royal visits, the city kept on growing in size, and finally in 1561 the Spanish Court was transferred from its location in Toledo to Madrid. The seat of the Spanish Court moved again to Valladolid in 1601, but it returned definitively to Madrid 5 years later.
The 19th century was a sad time for Madrid with bloody historical events such as the rising of the city against French occupation on May 2nd 1808, and the beginning of the Spanish war of Independence.
In the 20th century after the dead of General Franco, the Spanish Constitution of 1978 confirmed Madrid as capital city of Spain. In 1979, the first democratic local elections were held in Madrid to choose the first city mayor; the first governor of the city was Enrique Tierno Galván.
By this time Madrid had grown in size and population reaching the figure of 3 million inhabitants in the metropolitan area and nearly 6 million people in the whole province of Madrid.