Under the supervision of António Luís de Meneses, 1st Marquis of Marialva, the fort was constructed during the reign of King John IV in a Mannerist style, following an irregular pentagon design. This was done in order to reinforce the defence of the capital in the context of the Restoration War between 1640 and 1668, that culminated in the Treaty of Lisbon (1668) with Spanish recognition of Portuguese sovereignty. It was built to support the Fort of São Julião da Barra to its southwest, crossing fire with the Fort of São Lourenço do Bugio, situated in the middle of the estuary, and the Fort of Santo Amaro do Areeiro, situated between it and São Julião da Barra. It thus formed part of a line of fortifications that stretched from Cabo da Roca on the Atlantic coast to the Belém Tower, close to Lisbon. Its strategic position dominated the channel through which shipping still passes today to avoid shallow bars close to the banks. In 1644 it was already garrisoned by twenty soldiers, ten gunners and a chief of artillery, with five cannons, but the works were only completed in 1653.
In 1735, the fort was reported as being in a good state of repair, but its artillery was reduced to 2 pieces of 24-gauge cannon and another 12 of various calibres that were out of service. Repair works were carried out in the middle of the same century, including the application of tiles in the small chapel. However, soon after work was completed the fort and chapel were severely damaged by the earthquake of November 1, 1755, although many of the tiles have survived. A decade later work was carried out to expand the structure, beginning with the so-called New Battery.
In 1802, after the brief War of the Oranges in 1801, there were 24 artillery pieces of various calibres: eight on the original battery, twelve on a new battery, and four on the terrace above the strong house. In the context of the Peninsular War (1808–1814) the Fort of São João das Maias was integrated into the third of three lines of defence known as the Lines of Torres Vedras, at the extremity of a wall and trench designated "Military Work No. 110" out of a total of 152 works in the three lines.