COMPACT groups of galaxies have such high apparent densities that their members are separated in projection by only a few galactic radii, making them the most promising environment in the low-redshift Universe for studying the effects of galaxy merging. But the dynamical and evolutionary status of these groups is still subject to considerable uncertainty1-3, partly because of the bias introduced by the selection criteria used to identify them4. Using the Rosat X-ray telescope5, we have detected a large cloud of hot gas centred on the compact group HCG62. From the properties of this gas, rather than the galaxies themselves, we are able to infer both the distribution of dark matter (which extends significantly beyond the apparent optical confines of the group and dominates its total mass) and the evolution of the group as a whole. The compact core of galaxies seems to have formed as a result of orbital decay in a much more extended system, and should culminate in a final merger within a few billion years. We suggest that a new class of 'fossil' groups, consisting of a large elliptical galaxy embedded at the centre of an extended X-ray halo, awaits discovery by Rosat.