E-commerce, as a prominent feature of the digital economy era, is highly expected to promote economic growth and sustainable development. Based on the 2020 “China Rural Revitalization Survey” data, this study empirically analyzed the impact and mechanism of digital literacy on the discrepancy between the willingness and behavior of farmers in e-commerce sales. Eleven indicator items were selected, and factor analysis was used to obtain the comprehensive score of digital literacy. Firstly, benchmark regression was performed using the probit model, and then potential endogeneity issues were addressed using the IV probit method and endogenous conversion probit model. The following main conclusions were drawn: Digital literacy has a suppressive effect on the deviation between the willingness and behavior of farmers in e-commerce sales. Farmers with media operation literacy, information acquisition literacy, digital transaction literacy, e-commerce cognitive literacy, and digital social literacy have a 12.3%, 18.3%, 26.2%, 37.5%, and 21.9% reduction in the probability of deviation between the willingness and behavior of farmers in e-commerce sales compared to those without these literacy counterfactual assumptions. Digital literacy helps curb the deviation between farmers’ willingness and behavior in e-commerce sales by facilitating their access to financial resources and agricultural production services. This study demonstrates that enhancing the digital literacy of farmers will promote their willingness to convert e-commerce sales into behavior, help promote sustainable agricultural products more efficiently, and make important contributions to economic growth and sustainable development.