We explore the mechanism responsible for the ergodicity breaking in systems with long-range forces. In thermodynamic limit such systems do not evolve to the Boltzmann-Gibbs equilibrium, but become trapped in an out-of-equilibrium quasi-stationary-state. Nevertheless, we show that if the initial distribution satisfies a specific constraint-a generalized virial condition-the quasistationary state is very close to ergodic and can be described by Lynden-Bell statistics. On the other hand, if the generalized virial condition is violated, parametric resonances are excited, leading to chaos and ergodicity breaking.