Abstract The electronic speed governors are widely used in diesel generator sets (DGS). To develop and debug electronic speed governor, the best option is to build a hardware-in-the-loop (HIL) simulation system. In the HIL simulation system, the physical diesel engine is replaced with its mathematical model for reducing the cost and producing less emissions. To meet the requirement of closing to the real environment, the performance of mathematical model representatives is very important. This paper presents a diesel engine modeling method based on recurrent neural networks (RNNs). This mathematical model is identified and estimated using the real data from one physical DGS. The experimental results showed that the proposed model accurately reproduced the diesel engine output characteristics with the changes of electrical power loads. To validate the proposed model, the simulation experiment was conducted on the established HIL simulation system. In the simulation experiment, the rack displacement and rotational speed were measured from the physical part of the HIL simulation system. The simulation result has been confirmed that the proposed model could well simulate the loading and unloading processes of the DGS.