In 642 AD, after the Sasanian disaster at the hands of the Rashidun Caliphate at the Battle of Nihawand, much like Darius III, the last Sasanian king, Yazdegerd III, fled eastward and arrived in Margiana in 651 AD. Yazdegerd was well received by Mahoe Suri, the marzban of Merv, however, upon arrival Yazdegerd appointed his courtier Farrukhzad as marzban and ordered that Mahoe give absolute control of the city over to him. Mahoe refused and Farrukhzad advised the king to retreat to Tabaristan, which he ignored. Farrukhzad then left for Tabaristan, where he would later become king himself. As the Muslim army approached, Mahoe plotted with the Hepthalite ruler Nezak Tarkan to overthrow Yazdegerd who later discovered the plot and retreated to Marwir-Rawdh in southern Margiana. Mahoe agreed to pay tribute to the Rashidun general Ahnaf ibn Qais who began to consolidate Islam in Margiana and awaited reinforcements.