The village was given to Sunerico in the fifth century (460). The Suebi took over without much difficulty the village in 529. They were later followed by the Visigoths in the seventh century, when it was known as "Sancta Irena".
At the beginning of the eighth century, occupied by the Muslims, who called as "Chantirein" or "Chantarim" kept its urban structure and strengthened its agricultural, commercial and administrative vocation.
The town passed hands in control, eventually to the Almohad Caliphate. In the midst of the Christian Reconquest of the Iberian Peninsula, Portuguese forces under the command of King Afonso I of Portugal, the first king of Portugal (1112-1185) seized the village and surrounding on 15 March 1147 by surprise in an assault night in the Conquest of Santarém.
The town and its castle were in the path of the Almohad caliph Abu Ya'qub Yusuf I, who attacked the village in 1171 in hopes of expanding. Ferdinand II of León, son of D. Afonso Henriques, dispersed the siege which at the time was in Santarém. A new Muslim attack materializes in 1181, lying in the city the infant Sancho, and the assailants retreated before a counteroffensive of defenders.
In 1184, Caliph Abu Yaqub Yusuf made a new offensive to expand. He sent troops to attack, start the four-month-long Siege of Santarém.
King Denis of Portugal lived the final year of his life in the village. He died in 1325 in the castle.
Under the reign of Ferdinand (1367-1383), the sovereign commissioned the strengthening and expansion of the defenses, such as the reform of the port of Santiago in pointed arch in 1382. With his death, the Country fell into turmoil that came to be known as the 1383-85 Portuguese interregnum crisis. Within the castle walls the widow queen, Leonor Teles, took refuge after Christmas 1383 who once tried to raise banner in the city in support of his daughter, Beatriz, as queen of Portugal and Castile. Having requested the intervention of Castile, She met his son-in-law, John I of Castile, in January 1384 and gave status of landlord of the village and much of the kingdom, with the support of much of the Portuguese nobility.