An algorithm for the minimization of the energy of magnetic systems is presented and applied to the analysis of thermal configurations of a ferromagnet to identify inherent structures, i.e. the nearest local energy minima, as a function of temperature. Over a rather narrow temperature interval, skyrmions appear and reach a high temperature limit for the skyrmion density. In addition, the performance of the algorithm is further demonstrated in a self-consistent field calculation of a skyrmion in an itinerant magnet. The algorithm is based on a geometric approach in which the curvature of the spherical domain is taken into account and as a result the length of the magnetic moments is preserved in every iteration. In the limit of infinitesimal rotations, the minimization path coincides with that obtained using damped spin dynamics while the use of limited-memory quasi-newton minimization algorithms, such as the limited-memory Broyden–Fletcher–Goldfarb–Shanno (LBFGS) algorithm, significantly accelerates the convergence.