In 661 Naples, with the permission of the emperor Constans II, was ruled by a local duke, Basilius, whose allegiance to the emperor soon became merely nominal. In 763 the duke Stephen II switched his allegiance from Constantinople to the Pope. In 840 Duke Sergius I made the succession to the duchy hereditary, and thenceforth Naples was "de facto" totally independent. At this time the city was mainly a military centre, ruled by an aristocracy of warriors and landowners, even though it had been forced to surrender to the neighbouring Lombards much of its inland territory. Naples was not a merchant city as were other Campanian sea cities such as Amalfi and Gaeta, but had a respectable fleet that took part in the Battle of Ostia against the Saracens in 849. In any event, Naples did not hesitate to ally itself with infidels if it proved advantageous to do so: in 836, for example, Naples asked for support from the Saracens in order to repel the siege of Lombard troops coming from the neighbouring Duchy of Benevento. Later, Muhammad I Abu 'l-Abbas led its Muslim conquest of Naples and managed to sack it and take huge amount of its wealth.