This paper analyzes vulnerabilities in the security of large-scale language models (LLMs) using the Mixture-of-Experts (MoE) architecture and proposes SafeMoE, a novel secure fine-tuning method to address these vulnerabilities. Specifically, we highlight the problem that routing decisions for harmful inputs fluctuate significantly after fine-tuning, making them vulnerable to harmful fine-tuning (HFT) attacks. SafeMoE mitigates routing fluctuations by penalizing the difference between the routing weights of the initially safe-aligned model and the fine-tuned model, thereby maintaining security. Experimental results demonstrate that SafeMoE effectively mitigates HFT attacks and outperforms existing defense methods with minimal degradation in operational utility.