We present a method for including inelastic scattering in a first-principles density-functional computational scheme for molecular electronics. As an application, we study two geometries of four-atom gold wires corresponding to two different values of strain, and present results for nonlinear differential conductance vs. device bias. Our theory is in quantitative agreement with experimental results, and explains the experimentally observed mode selectivity. We also identify the signatures of phonon heating.