We consider the principle of least action in the context of fractional calculus. Namely, we derive the fractional Euler–Lagrange equation and the general equation of motion with the composition of the left and right fractional derivatives defined on infinite intervals. In addition, we construct an explicit representation of solutions to a model fractional oscillator equation containing the left and right Gerasimov–Caputo fractional derivatives with origins at plus and minus infinity. We derive a representation for the composition of the left and right derivatives with origins at plus and minus infinity in terms of the Riesz potential, and introduce special functions with which we give solutions to the model fractional oscillator equation with a complex coefficient. This approach can be useful for describing dissipative dynamical systems with the property of heredity.