The sudden emergence of the COVID-19 pandemic in early 2020 posed an enormous threat to public health. Vaccination is currently recognized as the most cost-effective preventive and control measure against the COVID-19 pandemic worldwide and is the key to constructing a line of defense against the virus, while the epidemic prevention policies adopted by governments have an important impact on the protective behavior of the public. The purpose of this study is to analyze the mechanism by which the stringency of epidemic prevention policies affects public vaccination willingness and to explore the mediating effect of public risk perception. A cross-sectional survey was conducted among 387 adults from December 2022 to June 2023 in China. A multiple linear regression model was used to explore the impact of epidemic prevention policy stringency on public vaccination willingness, and a hierarchical regression model was used to test the mediating effect of public risk perception. Our results showed that public vaccination willingness increased by approximately 45.5% for every one-unit increase in the stringency of the epidemic prevention policies, which shows that the stringency of epidemic prevention policies has a significant positive influence on public vaccination willingness. In addition, public risk perception increased by approximately 38.9% during the period of stringent government policies on epidemic prevention. For every one-unit increase in risk perception, public vaccination willingness increased by approximately 40.9%, and the relationship between the stringency of epidemic prevention policies and public vaccination willingness was partially mediated by risk perception. The stricter the epidemic prevention policies, the stronger the public vaccination willingness; risk perception plays a mediating effect between the stringency of epidemic prevention policies and public vaccination willingness. This finding is particularly important for exploring and analyzing the factors influencing public vaccination willingness and for improving public health.