The uprising was initially successful; the rebels gained Gegodog (1676), the majority of Java's north coast (1677), and the capital of Mataram (1677) from the royal army.
Amangkurat II, his son and successor, asked the VOC for assistance in exchange for cash payments and territorial concessions.
[11] In 1670 Kajoran introduced his son-in-law Trunajaya to the crown prince, who had recently been banished by the king due to a scandal, and the two forged a friendship that included a mutual dislike of Amangkurat.
[13] Initially, they settled in territories of the Banten Sultanate, but in 1674 they were expelled, and turned to piracy, raiding coastal towns in Java and Nusa Tenggara.
[12] Lacking a standing army, the bulk of Mataram's forces were drawn from troops raised by the king's vassals, who also provided the arms and supplies.
[14] The army used cannons, small firearms including flintlocks (Javanese: senapan, from Dutch snaphaens) and carbines, cavalry, and fortifications.
[15] Each VOC soldier had a sword, small arms, cartridges, carrying pouches and belts, smoke bombs, and grenades.
[25] The rebellion started with a series of raids from Makassarese pirates based in Demung against the trading towns on the northern coast of Java.
[26] Trunajaya entered into a pact and marriage alliance with the Kraeng of Galesong, the leader of the Makassarese, in 1675 and planned further raids.
[26] Given the failure of loyalist forces against the rebels, King Amangkurat I appointed a military governor in Jepara, the provincial capital of the northern coast, and reinforced the town.
A VOC fleet attack later destroyed the raiders' base in Demung, but they did not take action against Trunajaya in Madura.
[28][29] The loyalist army was routed, the king's uncle Pangeran Purbaya was killed, and the crown prince fled to Mataram.
[28] The towns fell easily, partly because their fortifications had been destroyed due to their conquest by Sultan Agung about 50 years earlier.
[28] Only Jepara managed to resist capture, due to the combined efforts of the new military governor and VOC forces who reinforced the town just in time.
[24] After gaining the victory in the Battle of Gegodog, the rebels proceeded westwards to conquer Mataram Sultanate's remaining towns on the north coast of Java (also known as the Pasisir).
Here, the rebels succeeded in defeating the Mataram forces and created an opportunity to capture Surabaya, a coastal city in East Java.
[32] In response to Mataram's request for intervention, VOC dispatched a large fleet containing Indonesian and European forces, commanded by Admiral Cornelis Speelman.
[34] The king fled west with the crown prince and his retinue, allowing the rebels to enter and plunder the capital with little fighting.
[34][21] The crown prince succeeded his father 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.
[36][21] 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.
[36] 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.
[36] His forces had recovered important coastal towns in Central Java, including Semarang, Demak, Kudus, and Pati.
[37] 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.
In September 1679, combined VOC, Javanese, and Bugis forces under Sindu Reja and Jan Albert Sloot defeated Raden Kajoran in a battle in Mlambang, near Pajang.
[41] In November, the VOC and allied Bugis forces under Arung Palakka expelled the Makassarese rebels' stronghold in Keper, East Java.
[7] In April 1680, after what the VOC considered the fiercest battle of the war, the rebellious lord of Giri was defeated and most of his family was executed.
However, during a ceremonial visit to the royal residence in Payak, East Java, on 2 January 1680,[43] he was personally stabbed by Amangkurat, and the king's courtiers finished him off.
[42] In addition to Trunajaya's forces, Amangkurat II continued to face opposition from his brother Pangeran Puger, who had taken the old capital in Plered and had claimed the throne for himself in 1677.
[48] However, in 1680 this policy required a high level of expenditure to maintain a military presence in Central and East Java, and this contributed to the VOC's financial decline.
[48] The payments promised by Amangkurat were not made, and by 1682 the king's debt to the VOC exceeded 1.5 million reals, about five times the amount of the royal treasury.