In 1796 while the Russians were Marching to Georgia and Transcaucasia, Agha Mohammad Khan in Tehran appointed Mirza Shafi Mazandarani as "kalantar" of Tehran and then left with an army to face Valerian Zubov. since In the invasion of Khorasan, Mirza Shafi went with Agha Mohammad Khan as an advisor. In Mashhad, on his advice, Shahrokh Afshar was tortured to expose Nader Shah's royal jewels. Mirza Shafi did not trust Ebrahim since he saw him as a traitor to Lotf Ali Khan and blieved he would do the same to Agha Mohammad Khan. Mirza Shafi, was also ambitious, he sought to discredit Ebrahim with Agha Mohammad Khan, so that with his removal, he would become Grand Vizier himself. Thus, a rivalry arose between the two, which sought to persuade Agha Mohammad Khan to dismiss the other.