The study followed the offspring of more than 8,000 mothers who had postnatal or antenatal depression.
The risk is around 1.3 times higher than normal at age 18, it found.
The study is published in JAMA Psychiatry. Lead researcher Dr Rebecca Pearson told the BBC: “Depression in pregnancy should be taken seriously and treated in pregnancy. It looks like there is a long-term risk to the child, although it is small.”
She said it was an association, not a causal link, and needed further investigation.
“The message is clear – helping women who are depressed in pregnancy will not only alleviate their suffering but also the suffering of the next generation.”
Prof Celso Arango of Gregorio Maranon General University Hospital, Madrid, said stress hormones may affect the child’s development in the womb.
“Women with depression would ideally be treated before getting pregnant, but if they are already pregnant when diagnosed with depression it is even more important that they are treated as it will impact on the mother and child.”
The researchers think different factors may be involved in antenatal and postnatal depression, with environmental factors such as social support having a bigger impact in postnatal depression.
The data comes from the Avon Longitudinal Study of Parents and Children – a long-term health research project, also known as Children of the 90s.
More than 14,000 mothers enrolled during pregnancy in 1991 and 1992, and the health and development of their children has been followed in detail since then.