In 661, Naples obtained from the emperor Constans IIthe right to be ruled by a local duke, one Basil, whose subjection to the emperor soon became merely nominal. Among his titles were patrikios and hypatos. At that time the Ducatus Neapolitanus controlled an area corresponding roughly to the present dayProvince of Naples, encompassing the area of Vesuvius, the Campi Flegrei, the Sorrentine Peninsula, Giugliano, Aversa, Afragola, Nola, and the islands of Ischia and Procida. Capri was later part of the duchy of Amalfi. He had authority over the neighbouring seaports of Gaeta, Amalfi, and Sorrento, though each of these was largely autonomous, especially during the later years of the Neapolitan duchy. In this era, the duchy coined monies with the effigy of the emperor and Greek inscriptions. Greek was the official language.
In 763, the duke Stephen II switched his allegiance from Constantinople to Rome, putting Naples under papal suzerainty. Already during the reign of the imperially appointed John I, the papacy had come to the duke's aid against the Lombards, while Byzantine assistance seemed remote. Stephen II's reign is considered a period of transition in the history of Naples: it moved away from the iconoclastic East and towards the papal West. The Byzantine Greeks were soon to become as much a threat to the Neapolitans as the Lombards. Sometime around the beginning of the ninth century, the dukes began striking coinage with Latin inscriptions, as Latin replaced Greek in official usage. Saint Januarius replaced the emperor on the coins. Acts were still dated by the imperial reign, but the emperor was of no consequence in regular Neapolitan affairs. In 813, when Leo V the Armenian called for the fleet of the entire ducatus to aid the Byzantine admiral in combating the Saracen pirates preying on Sicily, Duke Anthimus could ignore the order; only Amalfi and Gaeta responded with contingents. Apparently, the Neapolitans felt themselves practically independent already and their underlings felt themselves independent of Naples. The duchy was not yet hereditary; in 818, the patrician of Sicily appointed Theoctistus without imperial approval. He revoked this appointment, and appointed one Theodore II in 821, but he was chased from the city the same year in favour of the elected Stephen III. This Stephen first began to mint pieces with his own initials on them and not those of the Eastern Emperor.
Hereditary duchy
In 840, Duke Sergius I made the succession to the duchy hereditary, and thenceforth Naples was de facto independent. In this age, the city was mainly a military centre, ruled by an aristocracy of warriors and landowners, even though it had been compelled to surrender to the neighbouring Lombards much of its inland territory. Naples was not a merchant city as other Campanian sea cities like Amalfi and Gaeta, but had a respectable fleet who took part in the Battle of Ostia against the Saracens in 849. Anyway, Naples did not hesitate to ally with infidels if this turned to its advantage: in 836, for example, it asked support to the Saracens in order to push off the siege of Lombard troops coming from the neighbouring Duchy of Benevento. After its dukes rose to highest prominence under the Duke-Bishop Athanasius and his successors—of whom Gregory IV and John II participated at the Battle of the Garigliano in 915—Naples declined in importance in the tenth century, until it was captured by its traditional rival, Pandulf IV of Capua.
In 1027, duke Sergius IV donated the county of Aversa to a band of Norman mercenaries led by Rainulf Drengot, whose support he had needed in the war with the principality of Capua. In that period he could not imagine the consequences, but this settlement began a process which eventually led to the end of Naples' independence itself. Sergius cemented his position with marital alliances with the Normans, but when these broke down, he was abandoned by his mercenaries and retired to a monastery. His son, John V, cosied up to Guaimar IV of Salerno and eventually did homage to him. Naples was the last of the southern Italian states which the Normans had met when they first entered Italy. It survived the fall of the Lombard principalities: Capua, Salerno, Benevento. It had survived the fall of its fellow Greek duchies: Amalfi, Gaeta, Sorrento. In 1137, Duke Sergius VII was forced to surrender to Roger II of Sicily, who had had himself proclaimed King of Sicilyseven years earlier. Under the new rulers the city was administrated by a compalazzo, with little independence left to the Neapolitan patriciate. In this period Naples had a population of 30,000 and yet got its sustenance from the inland country: commerce activities were mainly delegated to foreign people, mainly from Pisa and Genova. Apart from the church of San Giovanni a Mare, Norman buildings in Naples were mainly lay ones, notably castles, walls and fortified gates.