After the fall of the Western Roman Empire, it was ruled by the Visigoths and, from the 8th century, by the Muslim emirate of Córdoba, with the name of Bulay (also Pulay).
In the 9th century it became the headquarters of the rebel Umar ibn Hafsun, who built extensive fortifications and reinforced the castle.
In 1370, due to the loyalty shown in the civil war, King Henry II of Castile gave Aguilar to Gonzalo Fernandez de Cordoba, first of a dynasty who held the town until the abolition of feudalism in the 19th century.
The town grew until the 1570s-1580s, after which it decayed, also due to several plague outbreaks which decimated the population, and to the shrinking level of the agriculture.
Salt springs exist in the neighborhood, and to the south there are two small lakes, Zoñar and Rincon, which abound in fish.