Not just Muslim invasions, but the powerful kings' emperors' conversion to another religion caused this transition. If the leader follows a different faith, it is normal for the commoners to follow their leader. This happened in several countries, e.g., the Maldives, Indonesia, Malaysia, etc. In India, there is no powerful leader who is Buddhist, which is the reason for the decline of Buddhism in India. But here in ancient Sri Lanka, it was required to be a Buddhist and the savior of the sacred relic of the tooth to become the ruler of the Island.
