This paper describes the effects of magmatic intrusions on petrology, mineralogy, and geochemistry of the late Palaeozoic coals from the Fengfeng−Handan coalfield, Hebei, China. The narrowly zoned coals of variable ranks, from high-volatile A bituminous (hvAb), through medium-volatile bituminous (mvb), low-volatile bituminous (lvb), semianthracite (sa), and anthracite (an), to meta-anthracite (ma) in the coalfield, were found to be best explained by magmatic inputs. The minerals derived from magmatic thermal alteration consist of pyrite, calcite, and ankerite, which mainly occur as fracture or vesicle fillings in the thermally altered high-rank coals. The variation in element concentrations with coal ranks (enrichment, depletion, and no variation) and mineralogical affinity were used to classify elements in coals into six groups, groups A−F. Elements in group A (B, F, Cl, Br, and Hg), group B (As, Co, Cu, Ni, and Pb), group C (Sr, Mg, Ca, Mn, and Zn), and Group D (U) were enriched in the altered coals, indicating that the magmatic inputs are the source of these elements. Group A elements are volatile elements that probably came from the hydrothermal solutions, then deposited or were driven off from an organic component in coal by magmatic heat, and then redeposited in the coal. Group B elements mainly distribute in the fracture or vesicle fillings of pyrites. The dominant carriers of group C elements are thermally altered calcite and ankerite. Uranium in group D occurs in organic-bonded and silicate associations. Group E elements, including Sb, Sc, and V, have a depletion trend in the altered coals, and the remaining elements in group F do not clearly vary in the unaltered, slightly altered, or altered coals. The element concentrations independent of coal ranks in groups E and F may suggest that these elements are inherent to the coal.