 In 1034 the Seljuks, who were enemies of the Yabghus, entered Khwarazm at the invitation of its Ghaznavid governor, Harun.In a battle between Shah Malik and the Seljuks the latter were defeated and forced to seek refuge in Ghaznavid Khurasan.In 1038 the Ghaznavid sultan Mas'ud invested Shah Malik with the title of Khwarazm Shah.