It is shown that the dynamics of cosmologies sourced by a mixture of perfect fluids and self-interacting scalar fields are described by the non-linear, Ermakov-Pinney equation. The general solution of this equation can be expressed in terms of particular solutions to a related, linear differential equation. This characteristic is employed to derive exact cosmologies in the inflationary and quintessential scenarios. The relevance of the Ermakov-Pinney equation to the braneworld scenario is discussed. reviews, see, e.g., [3]). The simplest mechanism for inflation utilises the potential energy associated with the self-interaction of a scalar inflaton field to drive the accelerated expansion. High redshift observations of type Ia supernovae suggest that the universe is experiencing another phase of accelerated expansion at the present epoch [4]. This, combined with the CMB data, presents a picture of the universe dominated by a dark energy component [5,6]. One possible source of this dark energy is a scalar quintessence field that interacts with baryonic and non-baryonic matter in such a way that its potential energy is currently dominating the cosmic dynamics [7]. The observations favour a model of structure formation where 70% of the energy density of the universe is presently in the form of quintessence [6]. The remaining fraction of the energy density is comprised of visible and cold dark matter which collectively act as a pressureless perfect fluid.The ekpyrotic scenario has recently been proposed as an alternative to the standard inflationary cosmology [8]. In this scenario the big bang is interpreted as the collision of two domain walls or branes travelling through a fifth dimension. Before the collision, the effective dynamics on the four dimensional branes is described by Einstein's gravity minimally coupled to a self-interacting scalar field. The field parametrizes the separation between the branes and at early times slowly rolls down a negative potential. This results in an accelerated collapse of the universe and since the field is minimally coupled, its energy density is related to the Hubble parameter by the standard Friedmann equation. Thus, self-interacting scalar fields play a central role in modern cosmology and in view of the above developments, it is important to investigate cosmologies that contain both a scalar field and a perfect fluid.In this paper, we develop an analytical approach to models of this type by expressing the cosmological field equations in terms of an Ermakov system [9,10,11]. In general, an Ermakov system is a pair of coupled, second-order, non-linear ordinary differential equations (ODEs) [11] and such systems often arise in studies of nonlinear optics [12], nonlinear elasticity [13], molecular structures [14] and quantum cosmology [15]. (For further references, see, e.g., Refs. [16]). In the one-dimensional case, the two equations decouple and the system reduces to a single equation known as the Ermakov-Pinney equation [9,17]. This is given by 1