Together with the Dutch, Pakubuwono defeated Amangkurat who fled east and received refuge from Surapati who had set up his own kingdom. The war dragged on for five years before the Dutch managed to install Pakubuwana. In August 1705, Pakubuwono I’s retainers and VOC forces captured Kartasura without resistance from Amangkurat III, whose forces cowardly turned back when the enemy reached Ungaran.