Changing gait is crucial for adaptive and smooth animal locomotion. Although it remains unclear what makes animals decide on a specific gait, energy efficiency is an important factor. It has been reported that the relationship of oxygen consumption with speed is U-shaped for each horse gait and that different gaits have different speeds at which oxygen consumption is minimized. This allows the horse to produce energy-efficient locomotion in a wide speed range by changing gait. However, the underlying mechanisms causing oxygen consumption to be U-shaped and the speeds for the minimum consumption to be different between different gaits are unclear. In the present study, we used a neuromusculoskeletal model of the rat to examine the mechanism from a dynamic viewpoint. Specifically, we constructed the musculoskeletal part of the model based on empirical anatomical data on rats and the motor control model based on the physiological concepts of the spinal central pattern generator and muscle synergy. We also incorporated the posture and speed regulation models at the levels of the brainstem and cerebellum. Our model achieved walking through forward dynamic simulation, and the simulated joint kinematics and muscle activities were compared with animal data. Our model also achieved trotting by changing only the phase difference of the muscle-synergy-based motor commands between the forelimb and hindlimb. Furthermore, the speed of each gait varied by changing only the extension phase duration and amplitude of the muscle synergy-based motor commands and the reference values for the regulation models. The relationship between cost of transport (CoT) and speed was U-shaped for both the generated walking and trotting, and the speeds for the minimum CoT were different for the two gaits, as observed in the oxygen consumption of horses. We found that the resonance property and the posture and speed regulations contributed to the CoT shape and difference in speeds for the minimum CoT. We further discussed the energy efficiency of gait based on the simulation results.