The first significant settlement in the Derbent area dates back to the 8th century BC. This region, with several interruptions, was under the control of Persian monarchs from the 6th century BC to the 4th century AD, serving as a satrapy of the Achaemenid Persian Empire. The modern name of the city is derived from the Persian word (دربند Darband), meaning “gate,” and came into use in the late 5th to early 6th century AD. At the same time, fortifications were built in Derbent, and the city also became a harbor.
In 643 AD, Derbent was captured by the Rashidun Caliphate (632–661 AD) and became known as Bab al-Abwab (Gate of Gates), and in the 10th century, the city became the center of an independent emirate. In 1067, the first Seljuk detachment entered Derbent, and by 1075, the city had fully come under the control of the Turkish Seljuks. In the 13th century, Derbent, along with the entire state of the Shirvanshahs, was conquered by the Mongols, and in 1395, Timur invaded the Terek valley through the Derbent Pass and delivered a crushing defeat to the Golden Horde on its banks. That same year, he handed Derbent over to Shirvanshah Ibrahim I, the ruler of an Iranian-speaking state on the territory of modern Azerbaijan.
In 1541, Derbent passed to Safavid Iran. As a result of the Caspian campaign (1722–1723), Russia gained control over Derbent and the surrounding territories. Due to the resettlement policy of Peter I, by 1723, large Armenian and Georgian settlements had formed in the city. Derbent returned to Iran after the signing of the Treaty of Ganja in 1735.
In the spring of 1795, Persian troops invaded Kakheti. Fulfilling its obligations under the Treaty of Georgievsk of 1783, the Russian government sent troops through Dagestan to Persia. On May 2, 1796, Russian troops approached Derbent and began an assault on the city. On May 10, a white flag was raised on the fortress wall.
With the ascension of Paul I to the throne and the subsequent change in the country’s foreign policy, Russian troops were withdrawn from Transcaucasia in December of the same year, and all the territories they had conquered were returned. Derbent remained part of Persia until the signing of the Treaty of Gulistan in 1813 at the end of the Russo-Persian War.
From the 1840s, the city experienced rapid economic growth, primarily related to the cultivation of madder (a plant used to produce a cheap dye).