Before becoming a kingdom, Mataram had been an area which was part of Pajang Kingdom and led by a regent named Ki Ageng Pemanahan. The position of Ki Ageng Pemanahan is a regent was then handed down to his so, Sutawijaya.
Please read Pajang Kingdom in article history : The development of Islamic in Pajang Kingdom
Sutawijaya was given a title ‘Senopati Alogo Sayidin Panatagama’ which means Commander in Chief and Religion Defender. The reign of Senopati (1586-1601) was full of rebellions. Many areas apposed the expansionistic policy of Senopati.
The following are some of the invasions conducted by Senopati :
1. In 1586 Senopati invaded Surabaya. But to avoid further bloodshed, a public figure who was also a ‘wali’ (ulama) named Sunan Giri, decided to submit to Senopati. So Surabaya submitted to Mataram not because it was defeated in a war.
Who is Sunan Giri? Please read : The role ulamas in the early development of Islam in Indonesia
2. In the same year (1586) Senopati attacked Madiun and Ponorogo and the war was won by Mataram.
3. In 1587, Mataram invaded Pasuruan, Panarukan and Blambangan all of which had not professed Islam at that time.
4. In 1595, Mataram attacked Cirebon and Galuh (West Java) and forced them to submit to Mataram.
Meanwhile, Pati and Demak rebelled against Mataram at the same time. The troops of the two regencies managed to approach the capital town of Mataram. However, Mataram’s commander finally succeeded in beating the troops of Pati and Demak.
After Senopati died (1601), he was succeeded by his son, Mas Jolang, who was dubbed Panembahan Seda Ing Krapayak (1601-1613). During the reign, he had to work hard to suppress the rebellion of Demak and Ponorogo for three years (1601-1613) but finally the rebellion could be suppressed by Mataram.
Not long after that, Surabaya also tried to seperate from Mataram (1612). Though Mas Jolang was able to take control of Mojokerto, Gresik, and the villages around Surabaya, he could not put an end to the rebellion until he died in 1613 and was buried at Krapayak (Kotagede).
The successor of Mas Jolang was Adipati Martapura who was sickly and incapable of running the government. Finally, he was replaced by his brother, Raden Rangsang, who was better known as Sultan Agung.
During his regn (1613-1645), Sultan Agung tried to ynite the whols Java under his control. For that purpose, in 1622 Sultan Agung attacked Surabaya but failed. In the end, however, he could force Gresik, Pamekasan, Sumenep, Pasuruan and also Surabaya to submit to Mataram, though he had to work very hard.
Sultan Agung’s next struggle was to take over Batavia which was under the control of VOC. For that purpose, he approached and persuaded Banten to work together to attack Batavia, but Banten refused.
After failing to persuade Banten, Mataram began to attack Batavia and Sultan Agung was supported by Dipati Ukur (Sumedang). Tumenggung (Regent) Suro Agul-agul, and Kyai Adipati Madurejo.
The attack was done twice, in 1628 and 1629, but the two failed because it turned out that the forces of VOC were much stronger than the forces of Mataram. In 1645, Sultan Agung died and was replaced by his son whose title was Amangkurat I (1645-1677).