We consider the problem of periodic motion planning and of designing stabilising feedback control laws for such motions in underactuated mechanical systems. A novel periodic motion planning method is proposed. Each state is parametrised by a truncated Fourier series. Then we use numerical optimisation to search for the parameters of the trigonometric polynomial exploiting the measure of discrepancy in satisfying the passive dynamics equations as a performance index. Thus an almost feasible periodic motion is found. Then a linear controller is designed and stability analysis is given to verify that solutions of the closed-loop system stay inside a tube around the planned approximately feasible periodic trajectory. Experimental results for a double rotary pendulum are shown, while numerical simulations are given for models of a spacecraft with liquid sloshing and of a chain of mass spring system.