We investigate the relevance of the Yarkovsky effect for the origin of kilometer and multikilometer near-Earth asteroids (NEAs). The Yarkovsky effect causes a slow migration in semimajor axis of main belt asteroids, some of which are therefore captured into powerful resonances and transported to the NEA space. With an innovative simulation scheme, we determine that in the current steady-state situation 100-160 bodies with H < 18 (roughly larger than 1 km) enter the 3/1 resonance per million years and 40-60 enter the ν 6 resonance. The ranges are due to uncertainties on relevant simulation parameters such as the time scales for collisional disruption and reorientation, their size dependence, and the strength of the Yarkovsky and YORP effects. These flux rates to the resonances are consistent with those independently derived by Bottke et al. (2002, Icarus 156, 399-433) with considerations based only on the NEA orbital distribution and dynamical lifetime. Our results have been obtained assuming that the main belt contains 1,300,000 asteroids with H < 18 and linearly scale with this number. Assuming that the cumulative magnitude distribution of main belt asteroids is N(< H) ∝ 10 γ' H with γ' = 0.25 in the 15.5 < H < 18 range (consistent with the results of the SDSS survey), we obtain that the bodies captured into the resonances should have a similar magnitude distribution, but with exponent coefficient γ = 0.33-0.40. The lowest value is obtained taking into account the YORP effect, while higher values correspond to a weakened YORP or to YORP-less cases. These values of γ are all compatible with the debiased magnitude distributions of the NEAs according to Rabinowitz et al. (2000, Nature 403, 165-166), Bottke et al. (2000b, Science 288, 2190-2194), and Stuart (2001, Science 294, 1691-1693). Hence the Yarkovsky and YORP effects allow us to understand why the magnitude distribution of NEAs is only moderately steeper than that of the main belt population. The steepest main belt distribution that would still be compatible with the NEA distribution has exponent coefficient γ' ∼ 0.3.