Finding the most stable structure of a solid is one of the central problems in condensed matter physics. This entails finding both the lattice type (e.g., fcc, bcc, and orthorhombic) and (for compounds) the decoration of the lattice sites by atoms of types $A$, $B$, etc. (``configuration''). Most approaches to this problem either assumed that both lattice type and configuration are known, optimizing instead the cell volume and performing local relaxation. Other approaches assumed that the lattice type is known, searching for the minimum-energy decoration. We present here an approach to the global space-group optimization (GSGO) problem, i.e., the problem of predicting both the lattice structure and the atomic configuration of a crystalline solid. This search method is based on an evolutionary algorithm within which a population of crystal structures is evolved through mating and mutation operations, improving the population by substituting the highest total-energy structures with new ones. The crystal structures are not represented by bit strings as in conventional genetic algorithms. Instead, the evolutionary search is performed directly on the atomic positions and the unit-cell vectors after a similarity transformation is applied to bring structures of different unit-cell shapes to a common basis. Following this transformation, we can define a crossover operation that treats, on the same footing, structures with different unit-cell shapes. Once a new structure has been generated by mating or mutation, it is fully relaxed to the closest local total-energy minimum. We applied our procedure for the GSGO in the context of pseudopotential total-energy calculations to the semiconductor systems Si, SiC, and GaAs and to the metallic alloy AuPd with composition ${\mathrm{Au}}_{8}{\mathrm{Pd}}_{4}$. Starting from random unit-cell vectors and random atomic positions, the present search procedure found for all semiconductor systems studied the correct lattice structure and configuration. In the case of ${\mathrm{Au}}_{8}{\mathrm{Pd}}_{4}$, the search retrieved the correct underlying fcc lattice, but energetically closely spaced $(\ensuremath{\sim}2\phantom{\rule{0.3em}{0ex}}\mathrm{meV}∕\mathrm{at.})$ alloy configurations were not resolved. This approach to GSGO opens the way to predicting unsuspected structures by direct optimization using, in the cases noted above, an order of $100$ total-energy ab initio calculations.