Examine the dynasties. Both the Yuan and the Qing were foreign dynasties and lasted quite a while. So an Islamic dynasty ruling China for a while is not a far off chance. So an invading dynasty could impose Islam and, as Islam can be adapted slightly differently, people might accept it. Look at Islam in the Phillipines. Even the staunch Catholic Spaniards could not eradicate it.
Islam would be like the "Keep your hair and lose your head" policy imposed by OTL Manchus. But as long as the new conquerors don't take away imperial examination and their privileges, the landed gentry would eventually comply.