Until the Middle Ages, Peniche was an island. However, siltation of the channel between the island and the community of Atouguia on the mainland, caused by sea currents and winds, eventually led to the sea being replaced by sand dunes, with Peniche becoming a peninsula. In the late 15th and early 16th centuries the area was the target of attacks by English, French and Barbary pirates, to which King Manuel I initially responded by installing four armed ships in Peniche. He also encouraged the idea of a permanent fortification on that part of the coast. In 1544, King John III recommended the construction of a castle on the peninsula and in the same year the most appropriate location to give protection to the town’s harbour was identified. Initial construction work was mainly carried out in 1557 and 1558 but work on the northeast and northwest walls continued until 1567. The design is believed to have been influenced by the castles built by Henry VIII of England, most notably Pendennis Castle in Falmouth.
King Sebastian I ascended the throne in 1568 and appointed D. Luís de Ataíde, 3rd Count of Atouguia, to the position of Viceroy of India (1568-1571). Work on the fortification was suspended until his return. D. Luis de Ataíde left for India for a second time in 1578, at which time the construction work was once again suspended. During the Spanish rule of Portugal (1581-1640), Philip II of Spain sent a military engineer to Peniche in 1589 to consolidate the fort and its walls and study possible improvements. In the same year British troops, under the command of Francis Drake, began a march on Lisbon at Peniche, in an unsuccessful attempt to restore Portuguese sovereignty.
In 1625 Philip IV of Spain highlighted the urgency of building a fort on the Berlengas islands, ten kilometres off the coast of Peniche, as these were often visited by corsairs.