Despite the great successes of the cold dark matter (CDM) model in explaining a wide range of observations of the global evolution and the formation of galaxies and large-scale structure in the Universe, the origin and microscopic nature of dark matter is still unknown. The most common form of CDM considered to date is that of weakly interacting massive particles (WIMPs), but, so far, attempts to detect WIMPs directly or indirectly have not yet succeeded, and the allowed range of particle parameters has been significantly restricted. Some of the cosmological predictions for this kind of CDM are even in apparent conflict with observations (e. g., cuspy-cored halos and an overabundance of satellite dwarf galaxies). For these reasons, it is important to consider the consequences of different forms of CDM. We focus here on the hypothesis that the dark matter is comprised, instead, of ultralight bosons that form a Bose-Einstein condensate, described by a complex scalar field, for which particle number per unit comoving volume is conserved. We start from the Klein-Gordon and Einstein field equations to describe the evolution of the Friedmann-Robertson-Walker universe in the presence of this kind of dark matter. We find that, in addition to the radiation-, matter-, and.-dominated phases familiar from the standard CDM model, there is an earlier phase of scalar-field domination, which is special to this model. In addition, while WIMP CDM is nonrelativistic at all times after it decouples, the equation of state of Bose-Einstein condensed scalar field dark matter (SFDM) is found to be relativistic at early times, evolving from stiff ((p) over bar = (rho) over bar) to radiationlike ((p) over bar = (rho) over bar /3), before it becomes nonrelativistic and CDM-like at late times ((p) over bar = 0). The timing of the transitions between these phases and regimes is shown to yield fundamental constraints on the SFDM model parameters, particle mass m, and self-interaction coupling strength lambda. We show that SFDM is compatible with observations of the evolving background universe, by deriving the range of particle parameters required to match observations of the cosmic microwave background (CMB) and the abundances of the light elements produced by big bang nucleosynthesis (BBN), including N-eff, the effective number of neutrino species, and the epoch of matter-radiation equality z(eq). This yields m >= 2.4 x 10(-21) eV/c(2) and 9.5 x 10(-9) eV(-1) cm(3) <=lambda/(mc(2))(2) <= 4 x 10(-17) eV(-1) cm(3). Indeed, our model can accommodate current observations in which N-eff is higher at the BBN epoch than at z(eq), probed by the CMB, which is otherwise unexplained by the standard CDM model involving WIMPs. We also show that SFDM without self-interaction (also called "fuzzy dark matter") is not able to comply with the current constraints from BBN within 68% confidence and is therefore disfavored.