The risk of contact infection among susceptible individuals in a randomly mixed population can be reduced by the presence of immune individuals and this concept is referred to as herd immunity1–3. The conventional susceptible-infectious-recovered (SIR) model does not feature a reduced risk of susceptible individuals in the transmission dynamics of infectious disease, therefore violates the fundamental of herd immunity4. Here we show that the reduced risk of contact infection among susceptible individuals in the SIR model can be attained by incorporating the proportion of susceptible individuals (model A) or the inverse of proportion of recovered individuals (model B) in the force of infection of the SIR model. We simulated the conventional SIR model and both new SIR models under the exact condition with a basic reproduction ratio of 3.0 and an expected herd immunity threshold of 0.667 (66.7%). All three models performed likewise at the initial stage of an epidemic. In the conventional SIR model, the epidemic continued until 94.0 % of the population had been infected and recovered, way above the threshold for eradication and control of the epidemic. Both models A and B simulated the epidemic waning when 66.7% and 75.6% of the population had been infected, as a result of the herd effect. As a result, model A provides a better framework for modelling vaccine-induced herd or population immunity, while model B provides a better framework for modelling infection-induced herd or population immunity. Our results demonstrate how the new modelling framework overcomes the drawback of the conventional SIR model and attain the effect of herd immunity in modelling outputs, which is important for modelling infectious disease in a randomly mixed population, especially for the COVID-19 pandemic.