As was the case with many of Malaysia's greatest trading civilizations, the Bujang Valley kingdom's prosperity made it an attractive target for outsiders. The region came under the influence of the Sumatran kingdom of Sri Vijaya in the 7th and 8th century, followed by a period during which Kedah was dominated by the Thai states to the north. Kedah's ancient civilization waned in importance by the 15th century, when Malacca assumed a more dominant role. The establishment of Islam in Kedah is due to Malacca's influence.
When Malacca fell to the Portuguese, the influence of its Sultanate over Kedah weakened. However, other powers soon asserted themselves in Kedah, including both the Portuguese and the rising Achenese, and by the end of the 18th century the Thai threat arose once more. Fearing renewed domination by its northern neighbours, Kedah appealed to the British for assistance. As inducements to a commitment, Kedah ceded first Penang (1796) and then the adjoining strip of coastal land (1800) to the British. Nonetheless, Kedah fell to the Thais in 1821. Thailand transferred their sovereignty to the British in 1909. With the exception of the period of occupation by the Japanese during World War II, Kedah remained under British influence until independence.