The castle of El Castillejo, the ruins of which can still be seen just above the village, was built by the Romans, but it was the Moors who settled the village after their conquest of Spain in 711, giving it the name of Qaryat Walyar. It remained in Moorish hands until 25 November 1491, when it was taken by Christian forces during the final phase of the Reconquista. In December 1499 the people of Güéjar took part in a rebellion which had in part been provoked by forced conversions, but they were defeated in January 1500. As a result, 2,500 villagers who had previously been baptized as Christians were taken to Granada and sold as slaves. 1568 saw the start of the Morisco Revolt, led by Aben Humeya, which lasted until 1571, although in Güéjar it was put down in 1569.