Abd al-Rahman I, founder of the Umayyad emirate in al-Andalus, had the mosque built in 785, and it was finished in roughly a year, helped along by columns and capitals taken from Roman and Visigothic buildings. When Ferdinand III of Castile captured the city in 1236, the building was turned into a cathedral dedicated to the Virgin Mary; the cathedral chapter has looked after it since that year, and Mass is still said there daily. It became a UNESCO World Heritage Site in 1984.
Later rulers kept enlarging the mosque while repeating its original arches. Abd ar-Rahman II lengthened the prayer hall by eight bays between 833 and 848; Abd ar-Rahman III rebuilt the courtyard and raised the first true minaret, finished in 958; his son al-Hakam II added twelve more bays to the south from 961; and in 987–988 the vizier Al-Mansur widened the whole building eastwards, adding eight naves. The eleven original north–south aisles thus grew to nineteen, and the hall now stands on approximately 850 columns of jasper, onyx, marble, granite and porphyry. Each arch has a horseshoe-shaped lower tier and a semicircular upper one, with voussoirs alternating between red brick and white stone.
The richest work is in al-Hakam II's extension at the southern end. A ribbed dome, now part of the Villaviciosa Chapel, marks the point where it starts, framed by screens of interlacing many-lobed arches. Further on is the maqsura, the space kept for the caliph during prayer, under three more ribbed domes, and the mihrab itself: a small seven-sided chamber behind a horseshoe arch, roofed by a shell-shaped cupola. Its arch and rectangular frame are covered in gold and glass mosaics, made with the help of a master craftsman whom the Byzantine emperor sent to the caliph, and the Kufic inscriptions worked into them quote the Qur'an and celebrate al-Hakam's expansion. It is the earliest known mihrab built as a real room instead of a simple niche.
In 1523 Bishop Alonso de Manrique began inserting a cross-shaped Renaissance church, the Capilla Mayor, into the centre of the prayer hall; the city council fought the plan, but Charles V allowed it to go ahead. Hernan Ruiz I and his son brought Gothic tracery to its vaults, Juan de Ochoa finished it in a Mannerist manner, and the elliptical dome over the crossing went up between 1599 and 1607. The mahogany choir stalls, carved by Pedro Duque Cornejo between 1748 and 1757, face a high altar whose paintings are by Antonio Palomino. The old minaret, once 47 metres high, now lies wrapped inside a Renaissance bell tower 54 metres tall, completed in 1617 and topped by a statue of Saint Raphael.
North of the prayer hall lies the old mosque courtyard, the Patio de los Naranjos, where orange trees, cypresses and palm trees grow in rows; its surrounding gallery was rebuilt by Hernán Ruiz I between 1510 and 1516. At the foot of the bell tower is the Puerta del Perdón, facing the Puerta de las Palmas, the ceremonial doorway into the former prayer hall. On the west side, the Puerta de San Esteban, once the Bab al-Wuzara through which the emir and his officials came in, was decorated under Muhammad I in 855. It is the earliest surviving gate to combine a horseshoe arch, voussoirs of alternating colour and a rectangular frame, a pattern that later Moorish gateways repeated.




