We present a measurement of the forward--backward asymmetry in top quark-antiquark production using the full Tevatron Run II dataset collected by the D0 experiment at Fermilab. The measurement is performed in lepton+jets final states using a new kinematic fitting algorithm for events with four or more jets and a new partial reconstruction algorithm for events with only three jets. Corrected for detector acceptance and resolution effects, the asymmetry is evaluated to be 10.6+-3.0 %. Results are consistent with the standard model predictions which range from 5.0% to 8.8%. We also present the dependence of the asymmetry on the invariant mass of the top quark--antiquark system and the difference in rapidities of top quark and antiquark.