In 1511 Malacca was conquered by Portugal (The news of Malacca's wealth attracted the attention of Manuel I, King of Portugal and he sent Admiral Diogo Lopes de Sequeira to find Malacca, to make a trade compact with its ruler as Portugal's representative east of India. The first European to reach Malacca and Southeast Asia, Sequeira arrived in Malacca in 1509. Although he was initially well received by Sultan Mahmud Shah trouble however quickly ensued.) , after which it was taken by the Dutch (Dutch Malacca (1641–1825) was the longest period that Malacca was under foreign control. The Dutch ruled for almost 183 years with intermittent British occupation during the Napoleonic Wars (1795–1818).) 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 rulers, to whom the rulers were bound to defer by treaty. The remaining five states in the peninsula, known as the Unfederated Malay States, while not directly under British rule, also accepted British advisers around the turn of the 20th century. Development on the Peninsula and Borneo were generally separate until the 19th century. Under British rule the immigration of Chinese and Indians to serve as labourers was encouraged. The area that is now Sabah came under British control as North Borneo when both the Sultan of Brunei and the Sultan of Sulu transferred their respective territorial rights of ownership, between 1877 and 1878. In 1842, Sarawak was ceded by the Sultan of Brunei to James Brooke, whose successors ruled as the White Rajahs over an independent kingdom until 1946, when it became a Crown colony.
In the Second World War the Japanese army invaded and occupied Malaya, North Borneo, Sarawak, and Singapore for over three years. During this time, ethnic tensions were raised and nationalism grew. Popular support for independence increased after Malaya was reconquered by Allied Forces. Post-war British plans to unite the administration of Malaya under a single crown colony called the Malayan Union met with strong opposition from the Malays, who opposed the weakening of the Malay rulers and the granting of citizenship to the ethnic Chinese. The Malayan Union, established in 1946 and consisting of all the British possessions in the Malay Peninsula with the exception of Singapore, was quickly dissolved and replaced by the Federation of Malaya, which restored the autonomy of the rulers of the Malay states under British protection. During this time, mostly Chinese rebels under the leadership of the Malayan Communist Party (The Malayan Communist Party (MCP), officially known as the Communist Party of Malaya (CPM), was founded in 1930 and laid down its arms in 1989. It is most famous for its role in the Malayan Emergency) launched guerrilla operations designed to force the British out of Malaya. The Malayan Emergency lasted from 1948 to 1960, and involved a long anti-insurgency campaign by Commonwealth troops in Malaya. After this a plan was put in place to federate Malaya with the crown colonies of North Borneo (which joined as Sabah), Sarawak, and Singapore. The proposed date of federation was 31 August 1963, however, the date was delayed until 16 September 1963 due to opposition from Indonesia's Sukarno and the Sarawak United Peoples' Party.
Federation brought heightened tensions including a conflict with Indonesia, Singapore's eventual exit in 1965, and racial strife. This strife culminated in the 13 May race riots in 1969. After the riots, the controversial New Economic Policy was launched by Prime Minister Tun Abdul Razak, trying to increase the share of the economy held by the bumiputera. Under Prime Minister Mahathir Mohamad there was a period of rapid economic growth and urbanisation beginning in the 1980s. The economy shifted from being agriculturally based to one based on manufacturing and industry. Numerous mega-projects were completed, such as the Petronas Towers, the North-South Expressway, the Multimedia Super Corridor, and the new federal administrative capital of Putrajaya. However, in the late 1990s the Asian financial crisis almost caused the collapse of the currency and the stock and property markets.