Between the 8th and 12th century Muslim forces occupied Elvas, resulting in the construction of the fortress. It was briefly conquered by forces loyal to Afonso Henriques around 1166, an action that was repeated in successive years with Moorish capture, and recapture, of the strategic point. In 1200 Sancho I encircled the citadel, and his successor, Sancho II made a tentative attempt to capture Elvas in 1226, at the same time Alfonso IX of León was trying to take Badajoz: although concerted, it was unsuccessful. This was followed in 1228 by another attempt, also unsuccessful, until 1230, after the castle and surrounding territory was abandoned by Muslim forces, who had received word that Alfonso IX had reached and was threatening Mérida.
The year before (1229) Sancho II had issued a foral (charter) for Elvas, which was later reaffirmed by King Afonso III in 1263. As a method of attracting further Iberian investments the concession of a fair, in 1262, helped to attract settlement to the region. This, along with further investments from the Crown resulted in the reconstruction of the castle and walled village between the 13th and 14th century, with the cerca Fernandina (walls of King Ferdinand), still under the reign of Afonso IV, that included 22 towers and 11 gates (including the important Gate of Olivença or Royal Gate).
Elvas was under siege from 1325 to 1327 from the forces of Alfonso XI of Castile, due to the continuing war during the reign of Afonso IV. This would continue for several years, first with a two-day siege in 1334; in 1337; and then in 1381, by Infante John of Portugal (son of King Peter I of Portugal and Inês de Castro) supported by Castilian forces, during the third protracted wars with Castile, during the reign of King Ferdinand (1381-1383). It was also besieged in 1385, by John II of Castille, during the Restoration Wars (1384-1387).
Following these battles, between 1488 and 1490, the castle underwent reconstruction, with alterations complete to the hexagonal tower, as well as the construction of a keep tower that was much taller and able to support artillery emplacements.