This area was located on the opposite side of the Tiber from the seven hills of Rome, and had not been enclosed within the ancient city's Aurelian Walls, built between 271 and 275. After Christianity had risen to prominence and the Roman Empire had collapsed, the area had to be defended through the construction of a new wall, since it housed St. Peter's Basilica.
The Leonine Wall, which defines Leonine City, was constructed by Pope Leo IV following the sacking by Muslim raiders of Old St. Peter's Basilica in 846. Built from 848 to 852 as the only extension ever made to the walls of Rome, this three-kilometre wall completely encircled the Vatican Hill for the first time in its history. An abortive start had been made by Leo III, but disturbances in the city had suspended work, and the Romans dismantled the sections that had been begun and used them in private constructions. Pope Leo IV used his estate workers, inhabitants from the surrounding countryside, Saracens captured after the sea battle of Ostia in 849 and funding from an imperial Frankish donation, to construct the wall, which ran in an enclosing U-shape from the riverbank at Hadrian's Mausoleum, soon to be known as the Castel Sant'Angelo, up the slopes of the Vatican Hill encircling the basilica and descending again to the river. The walling was constructed of tuff and tiling, forty feet high, with 44 strong towers at bowshot intervals. The massive round corner tower that still crowns the Vatican hill has its origins in this construction campaign.
Three new gates gave access to the newly enclosed Borgo. Two were in the stretch of wall that led back from the Castel Sant'Angelo: a small postern gate behind the fortified Mausoleum, called the Posterula S. Angeli and later, from its proximity to the Castello, the Porta Castelli, and a larger one, the principal gate through which emperors passed, near the church of St. Peregrino, called the Porta Peregrini, later the Porta S. Petri. A third gate opened the Leonine City to the rione of Trastevere. A festival celebrated the official completion of the walling, 27 June 852.
In 1083, after refusing to crown Henry IV as the next Holy Roman Emperor, Pope Gregory VII found himself under siege within the Leonine City. After Henry took the city, Gregory fled to Castel Sant'Angelo. Gregory attributed the loss of the Leonine City to famine and negligence and not so much to "the courage of Henry's men".
In 1870, when the military forces of the Kingdom of Italy captured Rome, overthrowing what was left of the Papal States, the Italian government intended to allow the pope to keep the Leonine City as a small remnant Papal State. However, Pope Pius IX would not agree to that arrangement, and thus there was a 59-year standoff, when the Popes were a "prisoner in the Vatican", settled in 1929 by the Lateran Treaty, which recognized the sovereignty and independence of Vatican City.