The Arab–Khazar wars were a series of conflicts fought between the Khazar Khaganate and successive Arab caliphates in the Caucasus region from to 799 CE. Smaller native principalities were also involved in the conflict as vassals of the two empires. Historians usually distinguish two major periods of conflict, the First Arab–Khazar War () and Second Arab–Khazar War (); the wars also involved sporadic raids and isolated clashes from the mid-seventh century to the end of the eighth century.

The wars were a result of attempts by the nascent Rashidun Caliphate to secure control of the South Caucasus (Transcaucasia) and North Caucasus, where the Khazars were already established since the late 6th century. The first Arab invasion began in 642 with the capture of the strategically important city of Derbent that guarded the eastern passage of the Caucasus along the Caspian Sea, and continued with a series of minor raids, ending with the defeat of a large Arab force led by Abd al-Rahman ibn Rabi'a outside the Khazar town of Balanjar in 652. Large-scale hostilities then ceased for several decades, apart from raids by the Khazars and North Caucasian Huns on the autonomous principalities of the South Caucasus during the 660s and 680s.

The conflict between the Khazars and the Arabs (now under the Umayyad Caliphate) resumed after 707 with occasional raids back and forth across the Caucasus Mountains, intensifying after 721 into a full-scale war. Led by the prominent generals al-Jarrah ibn Abdallah and Maslama ibn Abd al-Malik, the Arabs recaptured Derbent and the southern Khazar capital of Balanjar; these successes had little impact on the nomadic Khazars, however, who continued to launch devastating raids deep into the South Caucasus. In a major 730 invasion, the Khazars decisively defeated Umayyad forces at the Battle of Ardabil, killing al-Jarrah; in turn, they were defeated the following year and pushed back north. Maslama then recovered Derbent, which became a major Arab military outpost and colony, before he was replaced by Marwan ibn Muhammad (the future caliph Marwan II) in 732. A period of relatively localized warfare followed until 737, when Marwan led a massive expedition north to the Khazar capital Atil on the Volga Delta.

The 737 campaign marked the end of large-scale warfare between the two powers, establishing Derbent as the northernmost outpost of the Muslim world and securing Muslim dominance of the South Caucasus, but leaving the North Caucasus in Khazar hands. At the same time, continuing warfare weakened the Umayyad army and contributed to the fall of the Umayyad dynasty in 750, as a result of the Abbasid Revolution that established the Abbasid Caliphate. Relations between the Muslims of the Caucasus and the Khazars remained largely peaceful thereafter, and the Caucasus became an avenue of trade linking the Middle East to Eastern Europe. The resulting peace was interrupted by two Khazar raids in the 760s and 799 after failed efforts to secure an alliance through marriage between the Arab governors (or local princes) of the Caucasus and the Khazar . Occasional warfare between the Khazars and the Muslim principalities of the Caucasus continued until the collapse of the Khazar state in the late 10th century, but it never again matched the intensity and scale of the eighth-century war.

Background and motives The Caucasus as a frontier of civilizations

The Arab–Khazar wars were part of a long series of military conflicts between the nomadic peoples of the Pontic–Caspian steppe and the more settled regions south of the Caucasus. The two primary routes over the mountains, the Darial Pass (Alan Gates) in the centre and the Pass of Derbent (Caspian Gates) in the east along the Caspian Sea, have been used as invasion routes since classical antiquity. Consequently, defence of the Caucasus frontier against destructive raids by steppe peoples such as the Scythians and Huns came to be regarded as one of the chief duties of imperial regimes of the Near East. This is reflected in the popular belief in ancient and medieval Middle Eastern cultures that Alexander the Great had barred the Caucasus with divine assistance against the mythical hordes of Gog and Magog. According to historian Gerald Mako, the latter were stereotypical "northern barbarians" as conceived by the settled civilizations of Eurasia: "uncivilized savages who drank blood, who ate children, and whose greed and bestiality knew no limits". If Alexander's barrier failed and Gog and Magog broke through, the Apocalypse would follow.

Starting with Peroz I (), the shahs of the Sasanian Empire built a line of stone fortifications to protect the vulnerable frontier on the Caspian shore. When completed under Khosrow I (), these stretched over from the eastern foothills of the Caucasus to the Caspian Sea. The fortress of Derbent was the strategically crucial centre point of this fortification complex, as seen in its Persian name (). The Turkic Khazars appeared in the area of present-day Dagestan in the second half of the sixth century, initially as subjects of the First Turkic Khaganate. After the latter's collapse, they emerged as an independent, dominant power in the northern Caucasus by the seventh century. As the most recent steppe power in the region, early medieval writers came to identify the Khazars with Gog and Magog and the Sasanian fortifications at Derbent as Alexander's wall.

The Khazars are mentioned in medieval histories as being present in the Caucasus since the first centuries CE, but these are rejected as anachronistic by modern scholars. Some scholars have argued the Khazars must be identified with Turks who raided Sasanian Persia in the late 6th century, but again the evidence is unreliable, being derived from much later Arabic sources. Modern scholarship generally holds that the Khazars first campaigned in the South Caucasus during the Byzantine–Sasanian War of 602–628, as subjects of the Western Turkic Khaganate, who allied with the Byzantine Empire in the Third Perso-Turkic War. The Turks sacked Derbent in 627, broke through the local Sasanian defences, and joined the Byzantines in their siege of Tiflis. When Byzantine emperor Heraclius () invaded Persia proper the next year, 40,000 Turks joined him. Their contribution was decisive for ending the war in a Byzantine victory.

For a short while afterwards, as Sasanian power collapsed, the Turks exercised some control over Caucasian Iberia (approximately present-day Georgia), Caucasian Albania (the modern Republic of Azerbaijan) and Adharbayjan (modern Iranian Azerbaijan), while Armenia, the southwestern half of the South Caucasus, was in Byzantine hands. However, after the assassination of Tong Yabghu, the Western Turkic , around 630, the extension of Turkic control into the South Caucasus was abandoned, and the region returned to Sasanian influence by 632. The collapse of the West Turkic Khaganate led to the independence of the Khazars, then living in the Middle Volga region, and their emergence as an imperial power in their own right between the 660s and 680s, when they defeated Old Great Bulgaria and expanded into the North Caucasus.

Opposing armies In the Caucasus, the Khazars came into contact with the nascent Arab caliphate, which had extended its power over the South Caucasus in the 640s, after the first wave of the early Muslim conquests. The eastern Caucasus became the main theatre of the Arab–Khazar conflict, with the Arab armies aiming to gain control of Derbent (Arabic , 'Gate of Gates') and the Khazar cities of Balanjar and Samandar. Their locations have yet to be established with certainty by modern researchers, but both cities are referred to as Khazar capitals by Arab writers and may have been winter and summer capitals, respectively. Due to Arab attacks, the Khazars later moved their capital further north to Atil (Arabic ) in the Volga Delta..

Arabs Like other Near Eastern peoples, the Arabs were familiar with the legend of Gog and Magog, who appear in the Quran in the Arabicized form . After the Muslim conquests of the 7th and 8th centuries, their perceptions incorporated many of the cultural concepts of their new subjects. This was reflected in early Muslim geographic works, where the Caucasus was seen as part of a great continuous mountain chain that spanned the earth and divided the civilized lands of the south from the 'Land of Darkness' beyond, an idea deriving from Persian and possibly ancient Babylonian traditions. Consequently, according to Mako, the caliphs soon adopted the notion that it was their duty "to protect the settled, i.e. the civilized world from the northern barbarian". This imperative was reinforced by the Muslim division of the world into the House of Islam () and the House of War (), to which the Tengric pagan Turkic steppe peoples such as the Khazars were consigned.

While their Byzantine and Sasanian predecessors simply sought to contain the steppe peoples through fortifications and political alliances, historian David Wasserstein notes the leaders of the Arab caliphate were "expansionists interested in conquest"; their northward thrust threatened the survival of the Khazars as an independent polity. Historian Khalid Yahya Blankinship agrees, emphasizing the highly ideological nature of the Muslim caliphate and its dedication to the doctrine of , which in political terms entailed "the struggle to establish God's rule in the earth through a continuous military effort against the non-Muslims". The early Muslim state was geared toward expansion, with all able-bodied adult male Muslims subject to conscription. Its manpower pool was accordingly enormous and historian Hugh N. Kennedy estimates 250,000 to 300,000 men were inscribed as potential soldiers () in the provincial army registers . Kennedy stresses that this force was spread throughout the empire and many of the proved loath to answer summons if the prospects for an easy victory and plunder were low, but on the other hand, these numbers could be supplemented by unregistered Arab volunteers. This put the Arabs at a distinct advantage over their enemies: the entire nominal strength of the contemporary Byzantine army is estimated at 120,000 men, though revisionist historians put it at as low as 30,000.

Arab armies of the early Muslim conquests contained sizeable contingents of light and heavy cavalry, but relied primarily on their infantry. Arab cavalry was often limited to skirmishing early in a battle before dismounting and fighting on foot. Arab armies resisted cavalry charges by digging trenches and forming a spear wall behind them. This tactic indicates the discipline of Arab armies, particularly the elite Syrian troops, which in the Umayyad period served continuously rather than being called up for specific campaigns, and were a de facto professional, standing army. According to Kennedy, the Arabs' higher degree of training and discipline gave them an advantage against nomadic peoples like the Khazars.

In the 8th century, Arab armies were often accompanied by local forces provided by the various local potentates, who not only were under Arab suzerainty, but often enough had suffered themselves due to Khazar raids. Thus in 732 the presiding prince of Armenia, Ashot III Bagratuni, is known to have renewed an agreement for the employment of Armenian cavalry with the Arab army for three years, in exchange for 100,000 silver dirhams per year.

Khazars