 In ca.889, Justan aided the new Alid ruler Muhammad ibn Zayd against the ruler of Khorasan, Rafi ibn Harthama.In 900, the Samanids, who had at had become the new masters of Khorasan, defeated the Alids at Gurgan and conquered their domains in Tabaristan.