Nitrogen pollution resulting from excessive feed consumption poses a significant challenge for modern swine production. Precision nutrition technology seems to be an effective way to solve this problem; therefore, understanding the law of pig body composition deposition is a prerequisite. This study investigated the sex effects on growth performance, body composition, nutrient deposition, gut microbiota, and short-chain fatty acids (SCFA) in weaned piglets. Eighty weaned pigs were randomly allocated to 2 treatments according to the sex of pigs. An individual pig was considered as a treatment replicate. Six body weights (BW 5, 7, 11, 15, 20, and 25 kg) were chosen as experimental points; for each point 10 piglets close to the average BW (5 males and 5 females) were slaughtered, and there was one growth phase between each 2 BW points. Results indicated that the males had higher average daily gain (ADG) and average daily feed intake (ADFI) compared to the females (P < 0.05) at growth phases 15 to 20 kg BW and 20 to 25 kg BW. Meanwhile, males at 20 kg BW had higher body fat content than females (P < 0.10). Males showed a higher body fat (P < 0.05) deposition rate at phase 15 to 20 kg BW (P < 0.05) than females. For pigs at 20 kg BW, the relative abundance of RuminococcaceaeUCG-005, Clostridium, Christensenellaceae_R-7_group, and Peptostreptococcaceae was significantly increased in males (P < 0.05) but that of Bifidobacterium was decreased (P < 0.05). At 25 kg BW, the relative abundance of Ruminococcaceae_NK4A214_group, Fibrobacter, RuminococcaceaeUCG-009, Ralstonia, Klebsiel, and Christensenellaceae_R-7_group in males was higher when compared with females (P < 0.05). In terms of SCFA, females exhibited higher concentrations of propionate compared to males (P < 0.05). The results of the current study indicated that sex influenced fat deposition through changes in the composition of gut microbiota and the content of SCFA, which has significant implications for the realization of precision nutrition in modern swine production.