Trimethylamine N-oxide (TMAO) is a naturally occurring osmolyte that stabilizes proteins, induces folding, and counteracts the denaturing effects of urea, pressure, and ice. To establish the mechanism behind these effects, isotopic substitution neutron-scattering measurements were performed on aqueous solutions of TMAO and 1:1 TMAO-urea at a solute mole fraction of 0.05. The partial pair distribution functions were extracted using the empirical potential structure refinement method. The results were compared with previous results obtained with isosteric tert-butanol, as well as the available data from spectroscopy and molecular-dynamics simulations. In solution, the oxygen atom of TMAO is strongly hydrogen-bonded to, on average, between two and three water molecules, and the hydrogen-bond network is tighter in water than in pure water. In TMAO-urea solutions, the oxygen atom in TMAO preferentially forms hydrogen bonds with urea. This explains why the counteraction is completed at a 2:1 urea/TMAO concentration ratio, independently of urea concentration. These results strongly support models for the effect of TMAO on the stability of proteins based on a modification of the simultaneous equilibria that control hydrogen bonding between the peptide backbone and water or intramolecular sites, without any need for direct interaction between TMAO and the protein.