|Trunajaya's North Coast offensive|
|Part of the Trunajaya rebellion|
|Dutch East India Company (VOC)||Rebel forces|
|Commanders and leaders|
After his victory at the Battle of Gegodog (October 1676) in northeast Java, the Madurese rebel leader Trunajaya proceeded westwards to conquer Mataram Sultanate's remaining towns on the north coast of Java (also known as the Pasisir, today part of Indonesia). By January 1677, nearly all coastal towns from Surabaya to Cirebon (except Jepara) were taken.
The Trunajaya rebellion began in 1674 as Trunajaya's forces conducted raids against the cities under Mataram control. In 1676, a rebel army of 9,000 invaded East Java from their base in Madura, and took Surabaya – the principal city of East Java – shortly after. Mataram King Amangkurat I sent a large army to oppose him under the Crown Prince (later Amangkurat II), but this army was decisively defeated on 13 September at the Battle of Gegodog in northeast Java. After Gegodog, the Javanese north coast was open to Trunajaya's forces.
The rebel forces quickly proceeded westwards after the victory. The Javanese northern coastal region – also known as the Pasisir – contained many trading towns, such as Surabaya (already taken by Trunajaya before Gegodog), Tuban, Juwana, Pati, Jepara, Semarang and Kendal.
Trunajaya's forces met their first significant resistance in Jepara. In response to the rebellion, Amangkurat had installed a military man, Angabei Wangsadipa as governor in Jepara overseeing the entire northern coast. Subsequently, the town's defenses had been reinforced and additional cannons had been placed. Jepara's defender also had help from a Dutch East India Company (VOC) force of 200 men, who was reinforced by sea "just in time". They arrived there on 20 November 1676 and begin besieging the city. The joint Mataram-VOC defense, as well as with quarrel between the Madurese and Makassarese elements of the attackers, caused the attack to ultimately fail.
After failing to take Jepara, Trunajaya's captains – whose forces were augmented by Javanese defectors eager for booty – attacked other towns along the coast. The attacks were made easy because many towns had their fortifications dismantled during or after their conquest by Mataram's Sultan Agung about five decades before. Trading-towns were laid in ruin and ships were taken over to carry out further attacks. According to H. J. de Graaf, Mataram troops conducted "courageous" defenses of Kudus and Demak, but they ultimately fell. In 5 January 1677, Trunajaya reached as far west as Cirebon and took the town, after other coastal towns (except Jepara) had been taken or forced to acknowledge Trunajaya's authority. VOC forces in their Batavia headquarters prevented a further westward advance.