Khurramites

The Khurramites ( "Khorram-Dīnân", meaning "those of the Joyful Religion") were an Iranian religious and political movement with its roots in the Zoroastrian sect founded by Mazdak. An alternative name for the movement is the "Muḥammira" (, "Red-Wearing Ones"; in "Sorkh-Jâmagân"), a reference to their symbolic red dress.
History.
The sect was founded in the 8th century CE by the Persian cleric Sunpadh as a revitalisation of an earlier sect that had mixed Shī‘a Islam and Zoroastrianism. However, its true claim to fame was its adoption by Babak Khorramdin as a basis to rebel against the Abbasid Caliphate.
The sect grew out of a response to the execution of Abu Muslim by the Abbasids and denied that he had died but claimed that he would return as the Messiah. Thar message was further confirmed by the appearance of the named al-Muqanna‘ "The Veiled", who claimed that the spirit of God had existed in Muhammad, ‘Alī and Abu Muslim.
According to al-Tabari, the name first appeared in 736 when the missionary Kedas, a Hasemite, adopted "Din al-Korramiya". After the Hasemite Revolution, the Khorramis fought as rebels under Sonbadh, Moqanna, Babak and other leaders in various cities and regions.
The Khurramites in Azerbaijan were associated with Javidhan, a landlord who led one of the two Khurramite movements in Azerbaijan (from 807-808 to 816-817), with his headquarters being Badd Fort, near the Aras River. The leader of the other Khurramite movement was Abu Imran, who often clashed with Javidhan. During one of the clashes, probably in 816, Abu Imran was defeated and killed, and Javidhan was wounded and died three days later. Javidhan was succeeded by his heir, Babak Khorramdin, who married Javidhan's widow.
Babak's participation in the Khorrami movement was summarised by Waqed:
″Two rich men named Javidhan b. Shahrak (or Shahrak) and Abu 'Emran were then living in the highland around the mountain of Badd and contending for the leadership of the highland's Khorrami inhabitants. Javidhan, when stuck in the snow on his way back from Zanjān to Badd, had to seek shelter at Balalabad and happened to go into the house of Babak's mother. Being poor, she could only light a fire for him, while Babak looked after the guest's servants and horses and brought water for them. Javidhan then sent Babak to buy food, wine, and fodder. When Babak came back and spoke to Javidhan, he impressed Javidhan with his shrewdness despite his lack of fluency of speech. Javidhan therefore asked the woman for permission to take her son away to manage his farms and properties, and offered to send her fifty dirhams a month from Babak's salary. The woman accepted and let Babak go″.
Under Babak's leadership, the Khurammites proclaimed the divosion and the redistribution of the great estates and the end to the despotic foreign rule. Taking advantage of the turmoil created by the Abbasid Civil War, they began making attacks on Muslim forces in 816 in Iran and Iraq. 
Al-Tabari recorded that Babak started his revolt in 816–817. At first, Caliph al-Ma′mun paid little attention to the′s uprising because of the difficulty in intervening from far-away Khorasan, the appointment of his successor and the actions of al-Fadl ibn Sahl. Those circumstances paved the way for Babak and his supporters. The caliph sent General Yahya ibn Mu'adh to fight Babak in 819–820, but Babak was undefeated several times. Two years later, Babak overcome the forces of Isa ibn Muhammad ibn Abi Khalid.
In 824–825, Generals Ahmad ibn al Junayd and Zorayq bin ʿAlī bin Ṣadaqa were sent by the caliph to subdue Babakʿs revolt, but Babak defeated them and captured Jonayd. In 827–828, Moḥammad bin Ḥomayd was sent to overcome Babak and had several victories, but the last battle at Hashtadsar in 829, his troops were defeated by Babak.
When al-Ma'mun died in 833, he had failed against Babak, whose victories over Arab generals were associated with holding Badd Fort and the inaccessible mountain stronghold, according to Arab historians. They mentioned that his influence also extended to what is now Azerbaijan "southward to near Ardabīl and Marand, eastward to the Caspian Sea and the Šamāḵī district and Šervān, northward to the Mūqān (Moḡān) steppe and the Aras river bank, westward to the districts of Jolfā, Naḵjavān, and Marand".
In 833, many men from Jebal, Hamadan and Isfahan joined the Khorrami movement and settled near Hamadan. The new caliph, al-Mutasim, sent troops under Esḥāq bin Ebrāhīm bin Moṣʿab. The Khorramites were defeated in a battle near Hamadan. According to al-Tabari and Ali ibn al-'Asir, 60,000 Khurramites were killed.
In 835, al-Mutasim sent Ḥaydar bin Kāvūs Afšīn, a senior general and a son of the vassal prince of Osrūšana, to defeat Babak. Al-Mutasim set an price and allowances for Afshin that were unusually high. According to Said Nafisi, Afshin managed to attract Babak′s spies on his side by paying much more than Babak. When Afshin knew that Babek was aware that Boḡā the Elder had been sent a large amount of money by Afshin and was preparing to attack Boga, he used that information to pressure Babak into full co-operation, managed to have Babak's comrades killed and let Babak flee to Badd.
Before Afshin's departure, the caliph had sent a group under Abū Saʿīd Moḥammad to rebuild the forts demolished by Babak between Zanjān and Ardabīl. The Khorramits, led by under Moʿāwīa, made a failed attack on the Arabs that was recorded by al-Tabari as Babak’s first defeat.
The last battle between the Abbasid caliphate and the Khurrams occurred in Badd Fort on 837. The Khurramits were defeated, and Afšīn reached Badd Fort. After capturing Badd Fort, Babak went to near the Araz River. His goal was to join the Byzantine emperor, gather new forces and continue the struggle. Thus, it was announced that al-Mutasim would give a reward of two million dirhams to whoever handed Babak over alive. Babak's former ally, Sahl ibn Sumbat, handed Babak over to the Abbasids, and on March 14, 838, Babak was executed in the city of Samira. 
The Abbasid suppression of the rebellion led to the flight of many thousands of Khurramites to Byzantium, where they were welcomed by Emperor Theophilos, and they joined the Byzantine army under their Iranian leader, Theophobos.
Beliefs.
Al-Maqdisi mentions several facts. He observes that "the basis of their doctrine is belief in light and darkness"; more specifically, "the principle of the universe is Light, of which a part has been effaced and has turned into Darkness". They "avoid carefully the shedding of blood, except when they raise the banner of revolt". They are "extremely concerned with cleanliness and purification, and with approaching people with kindness and beneficence". Some of them "believed in free sex, provided that the women agreed to it, and also in the freedom of enjoying all pleasures and of satisfying one's inclinations so long as this does not entail any harm to others". (their name is most frequently derived from the Persian word "khurram" "happy, cheerful"). Regarding the variety of faiths, they believe that "the prophets, despite the difference of their laws and their religions, do not constitute but a single spirit". Naubakhti states that they also believe in reincarnation (metempsychosis) as the only existing kind of afterlife and retribution and in the cancellation of all religious prescriptions and obligations. They highly revere Abu Muslim and their imams. In their rituals, which are rather simple, they "seek the greatest sacramental effect from wine and drinks". As a whole, they were estimated by Al-Maqdisi as "Mazdaeans... who cover themselves under the guise of Islam".
Legacy.
According to Turkish scholar Abdülbaki Gölpınarlı the Qizilbash ("Red-Heads") of the 16th century – a religious and political movement in Azerbaijan that helped to establish the Safavid dynasty – were "spiritual descendants of the Khurramites".