Ahnaf captured Merw i-Rud, forcing Yazdegerd to flee to Balkh with his remaining supporters. Ahnaf was ordered by the Caliph Umar ibn al-Khattab to remain at Merv and not pursue Yazdegerd. However, upon learning that Yazdegerd had formed an alliance with Hepthalites beyond Margiana and was approaching Merv, Ahnaf rallied his forces and defeated Yazdegerd at the Battle of Oxus River. After his defeat, the Sasanian king attempted to hide in a mill where he was killed by a Margian miller, bringing the Sasanian Empire to an end.