In this study, a non-isothermal compressible cavitating flow simulation model for liquid ammonia in high-pressure injector, accounting for the phase change properties, was established. The model was validated using experimental data from existing literature. The cavitation phase change process of liquid ammonia within the injector nozzle was investigated, and the differences in cavitation distribution between ammonia and diesel were explored. The results indicate that with increasing injection pressure, the vapor volume fraction of ammonia increases linearly, while that of diesel fuel shows a rapid initial rise followed by a decelerating trend. In terms of flow coefficient, ammonia is lower than diesel, though the two values converge at higher injection pressures. Under low injection pressure, the heat absorbed by the cavitation phase change of ammonia exceeded the heat generated by the high-speed friction of ammonia flow against the nozzle wall, leading to a temperature drop at the nozzle inlet. Conversely, at high injection pressure, the temperature of ammonia on the nozzle wall increases by more than 20 K, resulting in a rapid rise in saturated vapor pressure and significantly intensifying the cavitation effect. Compared to ammonia, diesel experienced a higher temperature rise within the nozzle but exhibited smaller variations in saturated vapor pressure, making the temperature effect on cavitation less pronounced. Diesel’s higher density and viscosity resulted in lower flow velocities compared to ammonia, leading to more developed cavitation in the lower wall region of the nozzle and creating a higher pressure region on the upper wall of the nozzle, which was more distant from the nozzle inlet and inhibited cavitation development there. The research results provide theoretical support for the design of liquid ammonia injectors.