Cycling of a metallic glass between ambient and cryogenic temperatures can induce higher-energy states characteristic of glass formation on faster cooling. This rejuvenation, unexpected because it occurs at small macroscopic strains and well below the temperatures of thermally induced structural change, is important, for example, in improving plasticity. Molecular-dynamics simulations elucidate the mechanisms by which thermal cycling can induce relaxation (reaching lower energy) as well as rejuvenation. Thermal cycling, over tens of cycles, drives local atomic rearrangements progressively erasing the initial glass structure. This arises mainly from the heating stage in each thermal cycle, linked to the intrinsic structural heterogeneity in metallic glasses. Although, in particular, the timescales in MD simulations are shorter than in physical experiments, the present simulations reproduce many physically observed effects, suggesting that they may be useful in optimizing thermal cycling for tuning the properties of metallic glasses and glasses in general.