After the fall of the Western Roman Empire, Gaeta's history experienced a period of looting by both barbarians and by the Saracens but thanks to its position as a natural peninsula the city was fortified with walls walls on the top of the ancient medieval village arose the castle to defense of the town that gave shelter to the people from the surrounding areas who moved here for refuge and protection.
The Duchy of Gaeta remained independent until the beginning of the 12th century, Gaeta lost its independence and was conquered by Roger II of Sicily of the Altavilla dynasty, who nonetheless left numerous privileges to the city, such as its own currency and significant political autonomy, and allowed it to retain its ancient and glorious character as a maritime republic just as in Amalfi.
Thus saw the light of a kingdom that lasted for the next seven centuries, a unitary, independent and sovereign kingdom, the only one in all of Europe to preserve its territorial limits in full for so long, with Gaeta serving on several occasions as the "de facto" capital and strategic border town with the Church State (except for the period of the Spanish viceroyalty 1504-1707 and the Austrian rule 1707-1734).
Under the rule of the dynasty of Swabian origin, Gaeta saw its function as a "key gateway" to the kingdom particularly strengthened. Frederick II of Swabia had fortifications created to better defend the borders: in 1223 he built those for Gaeta Castle.
The Aragonese royals, realized how strategically relevant the possession of Gaeta for the defense of the kingdom, and had the fortifications increased by adding two new city walls.
Gaeta suffered as many as 14 sieges, coinciding with important and crucial historical events, starting with the defeat of the Duchy of Gaeta (with annexation to the Kingdom of Sicily) to the last siege, decisive for the destinies of the Kingdom of the Two Sicilies, the one held in 1860-'61 by General Enrico Cialdini's troops and after which the proclamation of the Kingdom of Italy took place.
With the Spanish rule, Gaeta became a viceroyalty, Gaeta's role as a "stronghold" was accentuated; Charles V had bastioned fortifications built on the slopes of Mount Orlando, so that they could withstand the most powerful weapons firearms.
In the year 1571 the papal fleet assembled in the port of Gaeta, here under the command of Admiral Marcantonio Colonna, on June 24 it set sail to join the rest of the Christian fleet to fight the Saracens. The flagship of the papal fleet under the admiral's command had hoisted the Standard of Lepanto
which the same commander had received on June 20, 1571 from Pope St. Pius V.
The battle was won by the Christian forces, and on his return to Gaeta Admiral Marcantonio Colonna kept his oath (he would donate the banner in case of victory to the same
Cathedral by placing it at the feet of the saint) before the relics of St. Erasmus of Antioch, protector of sailors and patron of the city. Today the banner is displayed in the diocesan museum.
On Nov. 25, 1848, Pope Pius IX took refuge in Gaeta as the guest of King Ferdinand II of Bourbon and remained there until Sept. 4, 1849, a period during which which Gaeta was the institutional seat and "de facto" capital of the State of the Church.
On February 13 February 1861 Francis II of Bourbon surrendered Gaeta, the last bastion of his kingdom, capitulating, after 102 days of bombardment, to the siege of the Savoy troops of General Enrico Cialdini (Siege of Gaeta 1860-1861): with the capitulation of Gaeta the Kingdom of the Two Sicilies ceased to exist.
The Borgo di Gaeta, a hamlet of Gaeta outside the walls, by Royal Decree of March 15, 1897, became an autonomous municipality and took the name "Comune di Elena" in honor of the then Princess Elena, future queen of Italy. Thirty years later, by Royal Decree of February 17, 1927, the municipalities of Gaeta and Elena were united again under the name Gaeta. The Borgo was identified as rione Porto Salvo, the fortified part of the city as rione Sant'Erasmo.
On 6 February 1927, Gaeta lost its ancient and famous status as a stronghold but became an important base of the Italian Navy, more specifically its port went on to constitute the main naval base in the Tyrrhenian Sea along with the port of La Spezia.
The city of Gaeta an important part of the ancient province of Terra di Lavoro of the Kingdom of Naples represented one of five district capitals. Within the Kingdom of Italy, the province was
maintained with the same name and capital and was subdivided, according to the Rattazzi law, into districts. Gaeta was a district capital until 1927 (along with Caserta, Sora, Nola and Piedimonte d'Alife).