In the Euclidean space of any dimension d, we consider the heat semigroup generated by the magnetic Schroedinger operator from which an inverse-square potential is subtracted in order to make the operator critical in the magnetic-free case. Assuming that the magnetic field is compactly supported, we show that the polynomial large-time behaviour of the heat semigroup is determined by the eigenvalue problem for a magnetic Schroedinger operator on the (d-1)-dimensional sphere whose vector potential reflects the behaviour of the magnetic field at the space infinity. From the spectral problem on the sphere, we deduce that in d=2 there is an improvement of the decay rate of the heat semigroup by a polynomial factor with power proportional to the distance of the total magnetic flux to the discrete set of flux quanta, while there is no extra polynomial decay rate in higher dimensions. To prove the results, we establish new magnetic Hardy-type inequalities for the Schroedinger operator and develop the method of self-similar variables and weighted Sobolev spaces for the associated heat equation.