Microbial community succession in raw milk determines its quality and storage period. In this study, carbon dioxide (CO2) at 2000 ppm was used to treat raw milk to investigate the mechanism of extending the shelf life of raw milk by CO2 treatment from the viewpoint of microbial colonies and metabolites. The results showed that the shelf life of CO2-treated raw milk was extended to 16 days at 4 ℃, while that of the control raw milk was only 6 days. Microbiomics analysis identified 221 Amplicon Sequence Variants (ASVs) in raw milk, and the alpha diversity of microbial communities increased (P < 0.05) with the extension of storage time. Among them, Pseudomonas, Actinobacteria and Serratia were the major microbial genus responsible for the deterioration of raw milk, with a percentage of 85.7%. A combined metagenomics and metabolomics analysis revealed that microorganisms altered the levels of metabolites, such as pyruvic acid, glutamic acid, 5'- cmp, arginine, 2-propenoic acid, and phenylalanine in the raw milk through metabolic activities, such as ABC transporters, pyrimidine metabolism, arginine and proline metabolism and phenylalanine metabolism, and reduced the shelf life of the raw milk. CO2 treatment prolonged the shelf life of the raw milk by inhibiting the abundance of Gram-negative aerobic bacteria, such as Acinetobacter guillouiae, Pseudomonas fluorescens, Serratia liquefaciens and Pseudomonas simiae.