Western Armenia had been under Byzantine control since the partition of the Kingdom of Armenia in AD 387, while Eastern Armenia had been under the occupation of the Sassanid Empire starting 428. Regardless of religious disputes, many Armenians became successful in the Byzantine Empire and occupied key positions. In Sassanid-occupied Armenia, the people struggled to preserve their Christian religion. This struggle reached its culmination in the Battle of Avarayr. Although the battle was a military defeat, Vartan Mamigonian's successor, Vahan, succeeded to force the Persians to grant religious freedom to the Christian Armenians in the Nvarsak Treaty of 484.
After the death of the Islamic prophet Muhammad in 632, the Arabs expanded their religion throughout the Middle East. In 639, with a force of 18,000 warriors, Abd‑er‑Rahman took Taron and sacked the country. In 642, the Muslims took Dvin, slaughtered 12,000 of its inhabitants and carried 35,000 into slavery.Prince Theodoros Rshtuni organized resistance and liberated the enslaved Armenians. However, Theodoros eventually accepted Arab rule of Armenia. Thus, in 645, the entirety of Armenia fell under Islamic rule. This period of 200 years was interrupted by a few restricted revolts, which never had a pan-Armenian character. Most petty Armenian families were weakened in favor of the Bagratunis and Artsrunis.
As Islamic power was waning, Ashot I of the Bagratuni family got more influence in Armenia. He became prince of princes in 861, and after a war against nearby Arab emirs, in 885, he was recognized as King of Armenia by both the Caliph of Baghdad and the Emperor of Constantinople. After more than 450 years of foreign occupation, Armenians finally reasserted their sovereignty in their ancestral lands. Despite Bagratid efforts to control all Armenian noble families, the Artsrunis and Siunis eventually broke off from central rule. Ashot III transferred the capital from Kars to Ani, which came to be known as the "city of 1001 churches". Ani became an important cultural and economic center in the whole region. Bagratid Armenia fell in 1045 to the Byzantines and then in 1064 to Seljuk Turks.