The influence of low dietary levels of free and encapsulated medium-chain fatty acids on their concentrations in the digesta, the gastric microbial ecology and bacterial metabolic products in the gastrointestinal tract (GIT) in weaned piglets was studied. Starting after weaning, 36 piglets were fed a diet without (Control) or with medium-chain fatty acids uncoated (MCFA) or coated with vegetable fat and lecithin (MCFAc). After 4 weeks, the animals were killed, and digesta from the stomach and different sections of the GIT were collected. The concentrations of caprylic (p < 0.001) and capric (p = 0.001) acids were higher in the stomachs of piglets fed diets MCFA and MCFAc compared to the Control group. The concentrations dropped rapidly along the GIT, regardless of encapsulation, and tended to be higher in groups MCFA and MCFAc compared to the Control. Compared to the Control group, ingestion of diet MCFAc led to an increase in the number of eubacteria (p = 0.001), enterobacteriaceae (p < 0.001), clostridial clusters I (p = 0.001) and IV (p = 0.019), Lactobacillus johnsonii (p < 0.001) and Lactobacillus amylovorus (p = 0.001) in gastric contents. A similar trend was seen with diet MCFA. Relative concentrations of short-chain fatty acids were characterised by lower propionic acid levels (p = 0.045), numerically (p < 0.1) higher acetic, lower n-butyric and i-valeric acid concentrations in the small intestine. Lactic acid concentrations were not significantly changed in the GIT, but ammonia concentrations increased (p < 0.001) in the distal small intestine in the MCFA and MCFAc groups. In conclusion, medium-chain fatty acids affected microbial ecology parameters in the gastric contents and bacterial metabolites in the small intestine. At low dietary levels, medium-chain fatty acids may be regarded as modulators of the gastric microbiota in weaned piglets.