IntroductionEnvironmental taxation is an essential regulatory tool for governments seeking to optimize agricultural production, enhance the environment, and guarantee food safety. Concerns exist, however, regarding the imposition of environmental taxes on agriculture, as this could be detrimental to the interests of agricultural producers and consumers. To address these challenges, it is essential to integrate agricultural production, environmental protection, and economic development, which can better comprehend the effects of agricultural environmental taxes on production decisions, the environment, the economy, and society.MethodsTo better comprehend the effects of agricultural environmental taxes on production decisions, the environment, the economy, and society, this paper constructs a mathematical model and analyzes optimal outcomes from a welfare perspective. The study examines the structure of consumer groups, classifying them as either green or non-green.Results and discussionFirst, when both consumer groups coexist on the market, imposing environmental taxes on non-green agricultural producers does not always result in a reduction in social welfare. Within a specific tax range, it is possible to accomplish a tripling of social welfare, agricultural producer welfare, and environmental benefits. Second, as the tax rate rises, the environment progressively improves while consumer surplus diminishes. Within a particular tax range, producer surplus and social welfare both increase. Third, as the proportion of green consumers in the market and ordinary consumers’ awareness of green agricultural foods increases, the positive impact of taxation on the environment decreases, while its positive impact on producer surplus and consumer surplus increases. Taxation can also have a positive effect on the social welfare under certain conditions.ContributionsFirst, we comprehensively investigate the feasibility of agricultural environmental taxation from a welfare perspective, considering market competition and segmentation, which fills a gap in previous studies. Second, we establish a reasonable range for taxation that simultaneously enhances social welfare, producer welfare, and environmental benefits. Third, we explore the relationship between market segmentation structure, ordinary consumers’ awareness of green agricultural foods, and welfare, providing insights into the different attitudes of countries and regions toward agricultural environmental taxation.