Evidence of modern human habitation in Malaysia dates back 40,000 years. The first inhabitants are thought to be Negritos. Traders and settlers from India and China arrived as early as the 1st century AD, establishing trading ports and coastal towns in the 2nd and 3rd centuries. Their presence resulted in strong Indian and Chinese influence on the local cultures, and the people of the Malay Peninsula adopted the religions of Hinduism and Buddhism. Sanskrit inscriptions appear as early as the 4th or 5th century. The Kingdom of Langkasuka arose around the 2nd century in the northern area of the Malay Peninsula, lasting until about the 15th century. Between the 7th and 13th centuries, much of the southern Malay Peninsula was part of the maritime Srivijaya empire. After the fall of Srivijaya, the Majapahit empire had influence over most of Peninsular Malaysia and the Malay Archipelago. Islam began to spread among Malays in the 14th century. In the early 15th century, Parameswara, a prince of the former Srivijayan empire, founded the Malacca Sultanate, commonly considered the first independent state in the peninsula. Malacca was an important commercial centre during this time, attracting trade from around the region. Parameswara became a Muslim, accelerating the spread of Islam.
In 1511 Malacca was conquered by Portugal, after which it was taken by the Dutch in 1641. In 1786 the British Empire established a presence in Malaya, when the Sultan of Kedah leased Penang to the British East India Company. The British obtained the town of Singapore in 1819, and in 1824 took control of Malacca following the Anglo-Dutch Treaty. By 1826 the British directly controlled Penang, Malacca, Singapore, and the island of Labuan, which they established as the crown colony of the Straits Settlements. By the 20th century, the states of Pahang, Selangor, Perak, and Negeri Sembilan, known together as the Federated Malay States, had British Residents appointed to advise the Malay