Amalfi held importance as a maritime power, trading grain from its neighbours, salt from Sardinia and slaves from the interior, and even timber, in exchange for the gold dinars minted in Egypt and Suria, which it used to buy the Byzantine silks that it resold in the West. Grain-bearing Amalfi traders enjoyed privileged positions in the Islamic ports. The Amalfi tables (tavole amalfitane) provided a maritime code that was widely used by the Christian port cities. Merchants of Amalfi were using gold coins to purchase land in the 9th century, while most of Italy worked in a barter economy. In the 8th and 9th century, when Mediterranean trade revived it shared with Gaeta the Italian trade with the East, while Venice was in its infancy, and in 848 its fleet went to the assistance of Pope Leo IV against the Saracens.
An independent republic from the 7th century until 1075, Amalfi extracted itself from Byzantine vassalage in 839 and first elected a duke in 958. It rivalled Pisa and Genoa in its domestic prosperity and maritime importance before the rise of the Republic of Venice. In spite of some devastating setbacks it had a population of some 70,000 to 80,000 reaching a peak about the turn of the millennium, during the reign of Duke Manso (966–1004). Under his line of dukes, Amalfi remained independent, except for a brief period of Salernitan dependency under Guaimar IV.
In 1073 the republic fell to the Norman countship of Apulia, but was granted many rights. A prey to the Normans who encamped in the south of Italy, it became one of their principal posts. However, in 1131, it was reduced by King Roger II of Sicily, who had been refused the keys to its citadel. The Holy roman Emperor Lothair, fighting in favour of Pope Innocent II against Roger, who sided with the Antipope Anacletus, took him prisoner in 1133, assisted by forty-six Pisan ships. The Pisans, commercial rivals of the Amalfitani, sacked the city; Lothair claimed as part of the booty a copy of the Pandects of Justinian which was found there.
In 1135 and 1137, the city was taken by the Pisans and rapidly declined in importance, though its maritime code, known as the Tavole amalfitiane, was recognized in the Mediterranean until 1570. A tsunami in 1343 destroyed the port and lower town, and Amalfi never recovered to anything more than local importance.
In medieval culture Amalfi was famous for its flourishing schools of law and mathematics. Flavio Gioia, traditionally considered the first to introduce the mariner's compass to Europe, is said to have been a native of Amalfi.