Strategies are needed to improve the dietary habits of children. The aim of the present study was to evaluate the effect of implementing a school food programme on the dietary quality of lunches consumed by school children aged 7–13 years compared with packed lunches brought from home. A secondary objective was to investigate if a possible effect would differ between the younger children and the older. A quasi-experimental study design with four intervention schools and four matched control schools was conducted. In total, 984 school children participated. Data on packed lunches were collected at baseline. At the 1st follow-up the children in the intervention schools were offered free school meals and at the 2nd follow-up children paid for their school meals. The control group had packed lunches at all measurements. A digital photographic method combined with a Meal Index of dietary Quality (Meal IQ) was used for dietary assessment. Multilevel modelling was employed for data analyses. The quality of dietary intake was improved when free school meals were offered (P = 0·004); if the school meals were paid for the use was limited and no difference in change in dietary quality was found (P = 0·343). The school food programme had no difference in effect according to age (P = 0·083). In conclusion, offering a free school meal had a positive effect on dietary quality of the lunches consumed by school children aged 7–13 years. No effect was measured when the school meals were not provided for free. The dietary effect did not depend on age.