In this paper we study the locomotion of a shape-changing body swimming in a two-dimensional perfect fluid of infinite extent. The shape changes are prescribed as functions of time satisfying constraints ensuring that they result from the work of internal forces only: conditions necessary for the locomotion to be termed self-propelled. The net rigid motion of the body results from the exchange of momentum between these shape changes and the surrounding fluid.The aim of this paper is three-fold.First, it describes a rigorous framework for the study of animal locomotion in fluid. Our model differs from previous ones mostly in that the number of degrees of freedom related to the shape changes is infinite. The Euler–Lagrange equation is obtained by applying the least action principle to the system body fluid. The formalism of Analytic Mechanics provides a simple way to handle the strong coupling between the internal dynamics of the body causing the shape changes and the dynamics of the fluid. The Euler–Lagrange equation takes the form of a coupled system of ordinary differential equations (ODEs) and partial differential equations (PDEs). The existence and uniqueness of solutions for this system are rigorously proved.Second, we are interested in making clear the connection between shape changes and internal forces. Although classical, it can be quite surprising to select the shape changes to play the role of control because the internal forces they are due to seem to be a more natural and realistic choice. We prove that, when the number of degrees of freedom relating to the shape changes is finite, both choices are actually equivalent in the sense that there is a one-to-one relation between shape changes and internal forces.Third, we show how the control problem, consisting in associating with each shape change the resulting trajectory of the swimming body, can be analysed within the framework of geometric control theory. This allows us to take advantage of the powerful tools of differential geometry, such as the notion of Lie brackets or the Orbit Theorem and to obtain the first theoretical result (to our knowledge) of control for a swimming body in an ideal fluid. We derive some interesting and surprising tracking properties: For instance, for any given shape changes producing a net displacement in the fluid (say, moving forward), we prove that other shape changes arbitrarily close to the previous ones exist, which lead to a completely different motion (for instance, moving backward): This phenomenon will be called Moonwalking. Most of our results are illustrated by numerical examples.