We describe a made-to-measure algorithm (χ2M2M) for constructing N-particle models of stellar systems from observational data (De Lorenzi Debattista, Gerhard, et al. (2007)), extending earlier ideas by Syer & Tremaine (1996). The algorithm properly accounts for observational errors. We implemented this algorithm in a parallel code NMAGIC and carried out a sequence of tests to illustrate its power and performance: (i) We reconstructed an isotropic Hernquist (1990) model from density moments and projected kinematics including higher-order Gauss-Hermite moments (Gerhard (1993), van der Marel & Franx (1993)). We gave NMAGIC two initial models, made from distribution function (Debattista & Sellwood (2000)), with different density distributions to start with. While both recovered the correct differential energy distribution and intrinsic kinematics, that with density closer to the density of the final model had smaller final deviations from the target observables, and a narrower distribution of weights. (ii) We built a self-consistent oblate three-integral maximum rotator model and compared how the distribution function is recovered from integral field and slit kinematic data. In these experiments we gave the algorithm a difficult problem to solve. Since the target system was maximally rotating, the weights of all counter-rotating particles were zero. Using density observables and either slit or integral field kinematics, NMAGIC was asked to recover this maximally rotating model starting from an isotropic spherical system. A good fit to the kinematic constraint data was achieved. These experiments also showed the advantage of integral field data over slit data for constraining the model. The different applications show that the χ2M2M algorithm is practical, reliable and can be applied to various systems. High quality dynamical models of galaxies can be achieved which match targets to ~1σ for plausible uncertainties in the observables, and without symmetry restrictions. We conclude that χ2M2M holds great promise for unraveling the nature of galaxies.