King Amangkurat I died during his retreat in Tegal in July 1677.
The crown prince succeeded his father and took the title of Amangkurat II, and was accepted by the Javanese gentry in Tegal (his grandmother's hometown) as well as by the VOC.
However, he failed to assert his authority in the nearby town of Cirebon, whose ruler decided to declare independence from Mataram with support from the Banten Sultanate.
Furthermore, his younger brother Pangeran Puger (later Pakubuwana I) took the now-ruined capital, refused entry to Amangkurat II's loyalists, and declared himself king under the title of Ingalaga Mataram.

Having no army or treasury and unable to assert his authority, Amangkurat decided to ally himself with the VOC.
At this point, Admiral Speelman was in Jepara, sailing there from Surabaya after hearing of the fall of the capital.
His forces had recovered important coastal towns in Central Java, including Semarang, Demak, Kudus, and Pati.
Amangkurat moved to Jepara on VOC ships in September 1677.
The king had to agree to sweeping concessions demanded by the VOC in exchange for restoring his monarchy.
He promised the VOC the income of all harbour towns on the northern coast.
The Priangan highlands and Semarang would be ceded to the VOC.
The king also agreed to recognize the jurisdiction of VOC courts over all non-Javanese residing in his domains.
Dutch historian H. J. de Graaf commented that by doing this, the VOC, being a corporation, engaged in a "hazardous speculation", which they expected to pay off in the future when their associate would regain his rule over Mataram.

VOC–Mataram forces made slow progress against the rebels.
By the beginning of 1678 their control was limited to several towns in the central northern coast.
In 1678 Speelman became the Director-General of the VOC, replacing Rijcklof van Goens, who became Governor-General (Speelman would become Governor-General in 1681).
His command in Jepara was handed over to Anthonio Hurdt, who arrived in June 1678.
King Amangkurat I died during his retreat in Tegal in July 1677. The crown prince succeeded his father and took the title of Amangkurat II, and was accepted by the Javanese gentry in Tegal (his grandmother's hometown) as well as by the VOC. However, he failed to assert his authority in the nearby town of Cirebon, whose ruler decided to declare independence from Mataram with support from the Banten Sultanate. Furthermore, his younger brother Pangeran Puger (later Pakubuwana I) took the now-ruined capital, refused entry to Amangkurat II's loyalists, and declared himself king under the title of Ingalaga Mataram.
Having no army or treasury and unable to assert his authority, Amangkurat decided to ally himself with the VOC. At this point, Admiral Speelman was in Jepara, sailing there from Surabaya after hearing of the fall of the capital. His forces had recovered important coastal towns in Central Java, including Semarang, Demak, Kudus, and Pati. Amangkurat moved to Jepara on VOC ships in September 1677. The king had to agree to sweeping concessions demanded by the VOC in exchange for restoring his monarchy. He promised the VOC the income of all harbour towns on the northern coast. The Priangan highlands and Semarang would be ceded to the VOC. The king also agreed to recognize the jurisdiction of VOC courts over all non-Javanese residing in his domains. Dutch historian H. J. de Graaf commented that by doing this, the VOC, being a corporation, engaged in a "hazardous speculation", which they expected to pay off in the future when their associate would regain his rule over Mataram.
VOC–Mataram forces made slow progress against the rebels. By the beginning of 1678 their control was limited to several towns in the central northern coast. In 1678 Speelman became the Director-General of the VOC, replacing Rijcklof van Goens, who became Governor-General (Speelman would become Governor-General in 1681). His command in Jepara was handed over to Anthonio Hurdt, who arrived in June 1678.
Trunajaya rebellion