Between 804 and 806 the Bulgarian armies thoroughly eliminated the Avar Khaganate, which had suffered a crippling blow by the Franks in 796, and a border with the Frankish Empire was established along the middle Danube or Tisza.