Amangkurat I took the throne of Mataram in 1646, succeeding Sultan Agung, who had expanded Mataram's realm to include most of Central and East Java, as well as a few overseas vassals in southern Sumatra and Borneo.
The early years of Amangkurat's reign were marked by executions and massacres against his political enemies.
In response to the failed coup attempt of his brother Pangeran Alit, he ordered massacres of Islamic men who he believed were complicit in Alit's rebellion.
Alit himself was killed during the failed coup.
In 1659 Amangkurat suspected that Pangeran Pekik, his father-in-law and the son of the conquered Duke of Surabaya who lived at the Mataram court after Surabaya's defeat, was leading a conspiracy against his life.
He ordered Pekik and his relatives killed.
This massacre of East Java's most important princely house created a rift between Amangkurat and his East Javanese subjects and caused a conflict with his son, the crown prince (later Amangkurat II), who was also Pekik's grandson.
Over the next few years, Amangkurat carried out a number of additional killings against members of the nobility who had lost his trust.

Raden Trunajaya (also spelled Trunojoyo) was a descendant of the rulers of Madura, who was forced to live in the Mataram court after Madura's defeat and annexation by Mataram in 1624.
After his father was executed by Amangkurat I in 1656, he left the court, moved to Kajoran, and married the daughter of Raden Kajoran, the head of the ruling family there.
The Kajoran family was an ancient family of clerics and was related by marriage to the royal family.
Raden Kajoran was alarmed at the brutality of Amangkurat I's rule, including executions of noblemen at court.
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.
In 1671 Trunajaya returned to Madura, where he used the crown prince's support to defeat the local governor and become the master of Madura.

Makassar was the principal trading center east of Java.
After the 1669 VOC victory over the Gowa Sultanate in the Makassar War, bands of Makassarese soldiers fled Makassar to seek their fortune elsewhere.
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.
The Mataram crown prince later allowed them to settle in Demung, a village in the eastern salient of Java.
In 1675 an additional band of Makassarese fighters and pirates arrived in Demung led by the Kraeng of Galesong.
These Makassarese itinerant fighters would later join the rebellion as Trunajaya's allies.
Amangkurat I took the throne of Mataram in 1646, succeeding Sultan Agung, who had expanded Mataram's realm to include most of Central and East Java, as well as a few overseas vassals in southern Sumatra and Borneo. The early years of Amangkurat's reign were marked by executions and massacres against his political enemies. In response to the failed coup attempt of his brother Pangeran Alit, he ordered massacres of Islamic men who he believed were complicit in Alit's rebellion. Alit himself was killed during the failed coup. In 1659 Amangkurat suspected that Pangeran Pekik, his father-in-law and the son of the conquered Duke of Surabaya who lived at the Mataram court after Surabaya's defeat, was leading a conspiracy against his life. He ordered Pekik and his relatives killed. This massacre of East Java's most important princely house created a rift between Amangkurat and his East Javanese subjects and caused a conflict with his son, the crown prince (later Amangkurat II), who was also Pekik's grandson. Over the next few years, Amangkurat carried out a number of additional killings against members of the nobility who had lost his trust.
Raden Trunajaya (also spelled Trunojoyo) was a descendant of the rulers of Madura, who was forced to live in the Mataram court after Madura's defeat and annexation by Mataram in 1624. After his father was executed by Amangkurat I in 1656, he left the court, moved to Kajoran, and married the daughter of Raden Kajoran, the head of the ruling family there. The Kajoran family was an ancient family of clerics and was related by marriage to the royal family. Raden Kajoran was alarmed at the brutality of Amangkurat I's rule, including executions of noblemen at court. 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. In 1671 Trunajaya returned to Madura, where he used the crown prince's support to defeat the local governor and become the master of Madura.
Makassar was the principal trading center east of Java. After the 1669 VOC victory over the Gowa Sultanate in the Makassar War, bands of Makassarese soldiers fled Makassar to seek their fortune elsewhere. 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. The Mataram crown prince later allowed them to settle in Demung, a village in the eastern salient of Java. In 1675 an additional band of Makassarese fighters and pirates arrived in Demung led by the Kraeng of Galesong. These Makassarese itinerant fighters would later join the rebellion as Trunajaya's allies.
Trunajaya rebellion