We present an efficient method for evaluating current-induced forces in nanoscale junctions, which naturally integrates into the nonequilibrium Green's function formalism implemented within density functional theory. This allows us to perform dynamic atomic relaxation in the presence of an electric current while evaluating the current-voltage characteristics. The central idea consists of expressing the system energy density matrix in terms of Green's functions. To validate our implementation, we perform a series of benchmark calculations, both at zero and at finite bias. First we evaluate the current-induced forces acting over an Al nanowire and compare them with previously published results for fixed geometries. Then we perform structural relaxation of the same wires under bias and determine the critical voltage at which they break. We find that although a perfectly straight wire does not break at any of the voltages considered, a zigzag wire is more fragile and snaps at 1.4 V, with the Al atoms moving against the electron flow. The critical current density for the rupture is estimated to be 9.6 × 1010 A/cm2, in good agreement with the experimentally measured value of 5 × 1010 A/cm2. Finally, we demonstrate the capability of our scheme to tackle the electromigration problem by studying the current-induced motion of a single Si atom covalently attached to the sidewall of a (4,4) armchair single-walled carbon nanotube. Our calculations indicate that if Si is attached along the current path, then current-induced forces can induce migration. In contrast, if the bonding site is away from the current path, then the adatom remains stable regardless of the voltage. An analysis based on decomposing the total force into a wind and an electrostatic component, as well as on a detailed evaluation of the bond currents, shows that this remarkable electromigration phenomenon is due solely to the position-dependent wind force. © 2011 American Physical Society.