The production of neutrons carrying at least 20% of the proton beam energy (xL > 0.2) in e+ p collisions has been studied with the ZEUS detector at HERA for a wide range of Q2, the photon virtuality, from photoproduction to deep inelastic scattering. The neutron-tagged cross section, ep → e′ Xn, is measured relative to the inclusive cross section, ep → e′ X, thereby reducing the systematic uncertainties. For xL > 0.3, the rate of neutrons in photoproduction is about half of that measured in hadroproduction, which constitutes a clear breaking of factorisation. There is about a 20% rise in the neutron rate between photoproduction and deep inelastic scattering, which may be attributed to absorptive rescattering in the γ p system. For 0.64 <xL <0.82, the rate of neutrons is almost independent of the Bjorken scaling variable x and Q2. However, at lower and higher xL values, there is a clear but weak dependence on these variables, thus demonstrating the breaking of limiting fragmentation. The neutron-tagged structure function, F2LN(3) (x, Q2, xL), rises at low values of x in a way similar to that of the inclusive F2(x, Q2) of the proton. The total γπ cross section and the structure function of the pion, F2π (xπ, Q2) where xπ = x/(1 - xL), have been determined using a one-pion-exchange model, up to uncertainties in the normalisation due to the poorly understood pion flux. At fixed Q2, F2π has approximately the same x dependence as F2 of the proton. © 2002 Published by Elsevier Science B.V.