Dietary protein restriction is one of the effective ways to reduce post-weaning diarrhoea and intestinal fermentation in piglets, but it may also reduce growth performance. The compensatory growth induced by subsequent protein realimentation may solve the issue. However, little research has been done on the impact of protein realimentation on the gut. In this study, the effects of protein restriction and realimentation on ileal morphology, ileal microbial composition and metabolites in weaned piglets were investigated. Thirty-six 28-day-old weaned piglets with an average body weight of 6.47 ± 0.04 kg were randomly divided into a control group and a treatment group. The CP level in the diet of the control group was 18.83% for the entire experimental period. The piglets in the treatment group were fed 13.05% CP between days 0 and 14 and restored to a diet of 18.83% CP for days 14 to 28. On day 14 and 28, six pigs from each group were sacrificed and sampled. It was found that the abundance of Lactobacillus and Salmonella in the ileal digesta was significantly lower in the treatment group than the control group on day 14, whereas the abundance of Clostridium sensu stricto 1, Streptococcus, Halomonas and Pseudomonas significantly increased in the ileal digesta of the treatment group on day 14 compared with the control group. In addition, reduced concentrations of lactic acid, total short-chain fatty acids (total SCFAs), total branched chain fatty acids, ammonia and impaired ileal morphology and mucosal barrier were observed in the treatment group on day 14. However, diarrhoea levels decreased in the treatment group throughout the experiment. During the succedent protein realimentation stage, the treatment group demonstrated compensatory growth. Compared with the control group, the treatment group showed increased abundance of Lactobacillus and reduced abundance of Salmonella, Halomonas and Pseudomonas in the ileum on day 28. The concentrations of lactic acid and total SCFAs increased significantly, whereas the concentration of ammonia remained at a lower level in the treatment group on day 28 compared with the control group. Overall, protein realimentation could improve ileal morphology and barrier functions and promote ileal digestive and absorptive functions. In conclusion, ileal microbial composition and metabolites could change according to dietary protein restriction and realimentation and eventually influence ileal morphology and barrier functions.