Maritime networks shifted Mahajapit vassals to Islam, moving it away from the Hindu-Buddhist faith. Islam had an advantage over other religions, because it was founded by merchants! Converting places to Islam only required books, while converting places to Hinduism required temples, which were much costlier. So in the 13th century, many locals in Indonesia began converting to Islam. Why? Well, we know that many Mahajapit vassals and enemies may have wanted some level of secure autonomy. This meant that those kingdoms would look to foriegn powers fro security. Before this, they would either look to Hindu India or Buddhist China for help. This is why Indonesia used to be Hindu-Buddhist. But in the 13th century, Islam was accepted in China under the Mongols. Islam also brought advanced Arabic writing, paper, and, most importantly, good relations with Muslim powers in India. This meant that the vast knowledge from the science of Hinduism and Buddhism could be translated to Arabic, and combined with the science from the Arabic World. And even more importantly, nations that wanted autonomy from the Mahajapit empire looked to Indo-Muslim powers or China, where the Mongols allowed Muslims to live. Later on, Zheng He was one of the main Chinese explorers who went on diplomatic missions into Southeast Asia. He was Muslim as well. So now the options for most kingdoms in Southeast Asia were this: Either stay as part of the Mahajapit empire(which was in a civil war), Declare themselves not loyal to the Mahajapit rule and then get crushed by Mahajapit navies, or convert to Islam, gain the favor of INDIA AND CHINA, learn Arabic knowledge, and then declare yourself independent. The Mahajapit empire can't do anything because you have two strong powers on your side.
In addition, Ibn Battuta was in Indonesia, and that helped Islam to spread into Indonesia.
Anyway, the year was 1398. The great Mahajapit empire was very strong and it indirectly controlled much of Indonesia. It sent ships to conquer the weaker kingdom of Singapore. Why? Because Singapore was the last bit of their old, strong rival Srivijaya. All the last remains of Srivijaya were taken to Singapore. Singapore is one of the example cities for converting to Islam. They had the expansionist Thai kingdom to the north to worry about as well. So while Singapore was being invaded, the king of Singapore (Srivijaya) fled to a strategic location. He converted to Islam, to gain support of India and Zheng He, and collected taxes from traders. He was right on the Strait of Malacca so he was prime to get rich from trade. He called his new empire the "Sultanate of Malacca". After getting a secure relation with China and India, he started to spread his influence through Indonesia.
The deal between China and the Sultanate of Malacca was this: China would get a check on Thai and Mahajapit power, and Malacca would get a strong navy and be secure. The deal between India and other Muslim powers and the Sultanate of Malacca was this: Convert to Islam, and I'll make sure I buy from you, paying taxes when I trade. Like this, many kingdoms freed thenselves of Mahajapit rule and converted to Islam. Mahajapit power began falling, and on top of that, the civil war hurt Mahajapit even more. Mahajapit was the last Hindu-Buddhist kingdom in Indonesia. They began losing money as the trade in Indonesia was shifting to Muslim powers. Eventually, Sumatra rebelled, and all Mahajapit controlled now were Java, Bali, the Spice Islands, and various small islands. However, eventually, Java itself was captured by a coalition of various Muslim kings. Now, Mahajapit was basically dead, as the Spice Islands had changed sides. Then, Mahajapit surrendered, but gave their culture to Bali. Bali continued to be a Hindu-Buddhist Island to this day, and still preserves old Mahajapit culture. Mahajapit theatre was one of the greatest forms of art, and Mahajapit history eventually became the spark that created the fire of Nationalism in Indonesia, which stopped the imperial Dutch rule centuries later. None of the previous answers really satisfy the question. The reason is clear: Bali is the last stronghold of Mahajapit culture after the rest of the Mahajapit empire converted to Islam, to get protected from Mahajapit by India and China.
Check out Extra Credits' video on this topic. You should also look at his previous videos for information on the Mahajapit Empire. You should also check out this histomap of the Mahajapit empire.
Hope this answers your question.