We measure phonon dispersion and linewidth in a single crystal of MgB2 along the Gamma-A, Gamma-M, and A-L directions using inelastic x-ray scattering. We use density functional theory to compute the effect of both electron-phonon coupling and anharmonicity on the linewidth, obtaining excellent agreement with experiment. Anomalous broadening of the E(2g) phonon mode is found all along Gamma-A. The dominant contribution to the linewidth is always the electron-phonon coupling.