We tested the hypotheses that supplementation of a diet with elemental Mg increases ruminal dissolved H2 (dH2) in rumen fluid, which in turn alters rumen fermentation and microbial community in goats. In a randomised block design, twenty growing goats were allocated to two treatments fed the same basal diet with 1·45 % Mg(OH)2 or 0·6 % elemental Mg. After 28 d of adaptation, we collected total faeces to measure total tract digestibility, rumen contents to analyse fermentation end products and microbial groups, and measured methane (CH4) emission using respiration chambers. Ruminal Mg2+ concentration was similar in both treatments. Elemental Mg supplementation increased dH2 at 2·5 h post morning feeding (+180 %, P<0·001). Elemental Mg supplementation decreased total volatile fatty acid concentration (−8·6 %, P<0·001), the acetate:propionate ratio (−11·8 %, P<0·03) and fungal copy numbers (−63·6 %, P=0·006), and increased propionate molar percentage (+11·6 %, P<0·001), methanogen copy numbers (+47·9 %, P<0·001), dissolved CH4 (+35·6 %, P<0·001) and CH4 emissions (+11·7 %, P=0·03), compared with Mg(OH)2 supplementation. The bacterial community composition in both treatments was overall similar. Ruminal dH2 was negatively correlated with acetate molar percentage and fungal copy numbers (P<0·05), and positively correlated with propionate molar percentage and methanogen copy numbers (P<0·05). In summary, elemental Mg supplementation increased ruminal dH2 concentration, which inhibited rumen fermentation, enhanced methanogenesis and seemed to shift fermentation pathways from acetate to propionate, and altered microbiota by decreasing fungi and increasing methanogens.