More than 2,500 10-year-old children each took four cognitive tests and researchers used satellite imagery to measure the amount of green space, parks, trees and plants near their house and school.
Children with more exposure to greenery improved the most in their cognitive tests and it was the green space surrounding their school that was shown to matter most.
Mark Nieuwenhuijsen, a researcher and one of the study’s authors, said: "The kids where there was more green around the school, we saw better cognitive development, so they did better on these tests.
"It was about a 5% difference over the time period."
The research team from Spain, Norway and US, led by Payam Dadvand, studied the children from 36 Barcelona schools over the course of a year, and published their findings in the National Academy of Sciences.
The majority of children showed improvement over time, but those with more exposure to greenery had a "superior" working memory and improved attentiveness.
During the study, researchers also looked at levels of traffic-related air pollution, which tends to be lower in areas with green spaces.
They found this to be an important factor in explaining the link between greenery and cognitive development.
The authors wrote, according to The Independent: "Our observed beneficial associations between greenness exposure and cognitive development could have been partly mediated by reduction in exposure to [traffic-related air pollution]."
However, they argued that the improvement couldn't be caused by this factor alone.
The authors listed various other possible reasons why green spaces were so beneficial for children's cognitive abilities.
These included less exposure to noise and because children with greater access to outside spaces were more likely to engage in outdoor exercise.
They also referred to the “biophilia” hypothesis - the idea that because humans evolved in certain kinds of green landscapes, we have a psychological need for them.
The authors added: "Improved cognitive development in children attending schools with more greenness could have lasting effects through the life-course."