In 1615, Alauddin Riayat Shah III signed a peace treaty with the Portuguese Malacca, and as a sign of gratitude, the Portuguese recognised Raja Bujang as the ruler of Pahang, replacing Alauddin Riayat Shah who was deposed earlier in 1615 by the Acehnese. However, the appointment was not recognised by Sultan Iskandar Muda of Acheh, which later invaded Pahang and forced Raja Bujang to flee to the islands of Lingga. At the same time, the Achehnese waged war with the new Sultan of Johor, Abdullah Ma'ayat Shah who was also forced to flee to Lingga.