In sum, Iran was dominated by three rules at that time. Muhammad Hussain Qajar possessed northern region. The southern area was under the control of Karim Khan Zand, and Khorasan on eastern area was ruled by the Afsharids. Muhammad Hussain Qajar had been killed, and Karim Khan Zand took over the power of whole Iran, including Khorasan; and founded the rule of Zand dynasty in Iran in 1163/1750.
Karim Khan Zand (1163-1193/1750-1779) had a friendly relation with Imam Abul Hasan Ali and his brother Pir Mirza Muhammad Bakir. Mirza Hussain Khan, the governor of Kirman treated the Imam with great respect, who charged certain towns and districts of Kirman under the control of the Imam. Later on, Karim Khan Zand appointed the Imam as the Beglarbegi of Kirman in 1170/1756. According to "The Cambridge History of Iran" (London, 1991, 7th vol., p. 85), "Eventually, Karim Khan appointed as beglerbegi an Ismaili Sayyid, Abul Hasan Ali Shah Mahallati, well respected locally for piety and generosity. His moral authority overrode the petty squabbles of the regional military governors, and his ample private income precluded any necessity for extortion or peculation."
The title beglarbegi means "Governor General", a term derived from Turkish beylerbeyi means "chief of the chief." In Iran, the Beglarbegi governed three sub-ordinate governors of a province, including deputy governor and lesser officials.
Karim Khan Zand died in 1193/1779, and Iran once again disintegrated. His brother Zaki Khan declared Muhammad Ali, the second son of Karim Khan, and his son-in-law as the second ruler of the Zands. Afterwards, Abul Fateh Khan, the elder son of Karim Khan was made a joint ruler with Muhammad Ali.
Meanwhile, a certain Aga Muhammad Khan Qajar escaped and reached to Mazandaran, and took charge of his tribe in Astrabad, and declared his rule in 1193/1779 immediately after the death of Karim Khan Zand. Zaki Khan dispatched his forces in command of his nephew, called Ali Murad Khan against Aga Muhammad Khan. Instead of fighting with Aga Muhammad Khan, he himself rebelled against the Zands, and captured Ispahan. He levied high taxes on the landlords and put to death who refused. He also tortured many persons, and once he is said to have thrown out 18 persons from his window to a ditch. The people in Ispahan rebelled, and killed Zaki Khan. Meanwhile, his brother Sadik Khan came in Shiraz and tore the eyes of Abul Fateh Khan from their sockets, and occupied Shiraz. In the succession disputes following Karim Khan Zand's death, the Imam is said to have lent his support to Sadik Khan, who was assisted in raising an army in Kirman. Sadik Khan restored the governorship of the Imam in Kirman. Imam's timely support to Sadik Khan had also avoided a massacre of the Ismailis. Meanwhile, the border region between Kirman and Afghanistan, including Narmashir, was raided by the Afghan and Baluchi troops of Azam Khan, an amir from Kandhar. Azam Khan was subdued by the Imam's forces, consisted of 7000 soldiers in command of Mirza Sadik, the cousin of the Imam. Later on, Azam Khan ravaged the districts of Kirman from Narmashir and reached as far as the entrance of the city of Kirman. This time, Abul Hassan Ali himself commanded his forces from Shahr-i Babak and inflicted a defeat to Azam Khan outside Kirman.
Ali Murad Khan raided Shiraz and killed Sadik Khan, the brother of Zaki Khan in 1195/1781. Then followed Jafar Khan (1779-1785), the son of Sadik Khan, who defeated Aga Muhammad Khan Qajar many times. His son Lutf Ali Khan, the last ruler of the Zand dynasty attacked the rising power of the Qajarids in Ispahan in 1205/1790, but his advisor, Haji Ibrahim abandoned his side and joined Aga Muhammad Khan. Lutf Ali Khan proceeded to Sirjan, intending to occupy Shahr-i Babak and the stronghold of the Imam, guarded by the Ataullahi Ismailis. Abul Hasan Ali had fortified and well-provisioned fortress in Shahr-i Babak under the command of Mirza Sadik. Lutf Ali Khan failed to gain Shahr-i Babak, and committed massacres of the Ismailis in the localities. He advanced to the city of Kirman. On that junction, Abul Hasan Ali refused to allow his entry in the city, and reinforced the city's defence and prepared to withstand a long siege. After one day of the siege, the inhabitants of the city sent out the Qadi and Shaikh al-Islam to the camp of Lutf Ali Khan with an offering of 20,000 tumans, imploring him to raise the siege and postpone the occupation of the city.
Hasan-i Fasai compiled his "Farsnama'yi Nasiri" in 1314/1896 (tr. by Heribert Busse, London, 1972, pp. 37-8), who writes, "Lotf Ali Khan, however, was full of pride and said that he would not raise the siege before Seiyed Abu'l Hasan Khan Kaheki, the governor of Kirman, and all the nobles and aldermen had come out of the city to the encampment. When the qazi and Shaikh al-Islam returned unsuccessful to the city, Abu'l Hasan Khan took greater care in the defence of the fortress than he had done before. When the winter came and roads and paths were blocked by snow and rain, the camp was cut off from provisions. For some time the people in the camp were satisfied with eating the meat of horses and donkeys, and patiently endured snow and rain. When things, however, became unbearable, the soldiers folded their tents and moved off. Lotf Ali Khan could not but do the same, and in the month of Jomadi I of that year (1205/January, February, 1791), he returned to Shiraz."