We have developed a least-squares refinement procedure that in an automated way performs three-dimensional alignment and averaging of objects from multiple reconstructions. The computer implementation aligns the three-dimensional structures by a two-step procedure that maximizes the density overlap for all objects. First, an initial average density is built by successive incorporation of individual objects, after a global search for their optimal three-dimensional orientations. Second, the initial average is subsequently refined by excluding individual objects one at a time, realigning them with the reduced average containing all other objects and including them into the average again. The refinement is repeated until no further change of the average occurs. The resulting average model is therefore minimally biased by the order in which the individual reconstructions are incorporated into the average. The performance of the procedure was tested using a synthetic data set of randomly oriented objects with Poisson-distributed noise added. The program managed well to align and average the objects at the signal/noise ratio 1.0. The increase in signal/noise ratio was in all investigated cases almost equal to the expected square root of the number of objects. The program was also successfully tested on a set of authentic three-dimensional reconstructions from an in situ specimen containing Escherichia coli 70S ribosomes, where the immediate environment of the reconstructed objects may also contain variable amounts of other structures.