The history of arrival and spread of Islam in Indonesia is unclear. One theory states it arrived directly from Arabia before the 9th century, while another credits Sufi merchants and preachers for bringing Islam to Indonesian islands in the 12th or 13th century either from Gujarat in India or directly from the Middle East. Before the arrival of Islam, the predominant religions in Indonesia were Buddhism and Hinduism (particularly its Shaivism tradition).
Initially, the spread of Islam was slow and gradual. Though historical documents are incomplete, the limited evidence suggests that the spread of Islam accelerated in the 15th century, as the military power of Melaka Sultanate in Malaysia and other Islamic Sultanates dominated the region aided by episodes of Muslim coup such as in 1446, wars and superior control of maritime trading and ultimate markets. By the time European merchants such as Portuguese and Dutch traders began actively trading in Indonesia in the 16th century, Buddhism and Hinduism were extinct in the major islands of Indonesia, except for pockets such as Bali which became the refuge for the Hindus from other Indonesian islands after Muslim Sultanates and Hindu kingdom wars in the 15th century. The eastern islands of Indonesia remained largely animist until the 17th and 18th centuries when Christianity became predominant in those areas.
The spread of Islam was initially driven by increasing trade links outside of the archipelago. Traders and the royalty of major kingdoms were usually the first to convert to Islam. Dominant kingdoms included Mataram in Central Java, and the sultanates of Ternate and Tidore in the Maluku Islands to the east. By the end of the 13th century, Islam had been established in North Sumatra; by the 14th in northeast Malaya, Brunei, the southern Philippines and among some courtiers of East Java; and the 15th in Malacca and other areas of the Malay Peninsula. Although it is known that the spread of Islam began in the west of the archipelago, the fragmentary evidence does not suggest a rolling wave of conversion through adjacent areas; rather, it suggests the process was complicated and slow.