The mouth of the Mira River has been of great importance for maritime and river navigation since ancient times, due to its location and good mooring conditions, in addition to being the only port located along the coastal strip between Sines and Cape Saint Vincent. It was used at least from the Roman period, as can be seen from the discovery of anchors and pottery fragments, having continued this function throughout the Middle Ages, constituting a secondary port for the port structures that served the town of Odemira. Its importance grew from the 12th century onwards, when the Mira River began to suffer from increasingly severe silting. Despite the presence of the natural port, the area itself was practically uninhabited until the settlement was founded, by royal decree of King John II. However, one of the main threats to the population was the attacks of Muslim pirates coming from North Africa. One of the biggest attacks took place during the beginning of the reign of John II, when the village was sacked and burned, to the point of being almost completely deserted, since the inhabitants abandoned it, taking refuge in the interior. In order to protect the population, the monarch offered fifty outlaws the right of asylum, under the condition that they help defend the inhabitants from pirates and corsairs. In 1512, it received a charter from King Manuel.
Although the installation of outlaws in Vila Nova de Milfontes reduced the attacks, it did not eliminate the threat of the pirates. In 1590, the corsairs staged a major assault, during which the town was almost completely destroyed. Thus, in 1598, the Neapolitan engineer Alexandre Massai was appointed by the Council of War to reconnoitre the area around the mouth of the Mira River, and find out how to organize its defense against pirates. The fort was built between 1599 and 1602, during the Habsburg period, and was also planned by Alexandre Massai.