The sultanate has its origin as a vassal to Melaka, with its first Sultan was a Melakan prince, Muhammad Shah, himself the grandson of Dewa Sura, the last pre-Melakan ruler of Pahang. Over the years, Pahang grew independent from Melakan control and at one point even established itself as a rival state to Melaka until the latter's demise in 1511. In 1528, the last Sultan of Melaka, Mahmud Shah died. Pahang joined forces with his successor, Alauddin Riayat Shah II who established himself in Johor to expel the Portuguese from the Malay Peninsula. Two attempts were made in 1547 at Muar and in 1551 at Portuguese Malacca. However, in the face of superior Portuguese arms and vessels, the Pahang and Johor forces were forced to retreat on both occasions.