HOW THE RESEARCH WAS CARRIED OUT
The researchers, from the Charité University, Berlin, analysed cortisol levels in 70 pregnant women.
The women provided saliva samples five times a day for four consecutive days during the early, middle and late stages of their pregnancies.
At four weeks old, the babies underwent MRI scans while sleeping.
Two years later, 45 of the children's mothers reported on how often their youngsters seem sad, lonely, worried or shy, as well as if they have trouble sleeping, enjoy hobbies and get along with others.
HIGH CORTISOL CAUSES DEPRESSION IN GIRLS ONLY
Study author Dr Claudia Buss said: "Higher maternal cortisol during pregnancy was linked to alterations in the newborns' functional brain connectivity, affecting how different brain regions can communicate with each other."
The altered connectivity occurs in a region of the brain involved in processing emotions, which appears to cause children to develop depression and anxiety two years later.
Dr John Krystal, editor of the journal Biological Psychiatry, where the research was published, said: "Many mood and anxiety disorders are approximately twice as common in females as in males.
"High maternal levels of cortisol during pregnancy appear to contribute to risk in females, but not males.
"This paper highlights one unexpected sex-specific risk factor for mood and anxiety disorders in females."
JUST TWO ALCOHOLIC DRINKS A MONTH DURING PREGNANCY RAISES A CHILD'S RISK OF HAVING A LOW IQ AND ADHD
This comes after research released last July suggested consuming just two alcoholic drinks a month during pregnancy raises a child's risk of having low a IQ and attention deficit hyperactive disorder (ADHD).
Youngsters whose mothers drank while expecting score six points lower on IQ tests and are more likely to have poor attention skills than those whose mums went teetotal, a study by the University Hospital Erlangen found.
Such children have 193 mutated genes, which are associated with brain cell development, the research adds.
Previous studies suggest youngsters who were exposed to alcohol in the womb are more likely to suffer from hyperactivity and impulsive actions.
The NHS and Centers for Disease Control and Prevention recommend pregnant women or those trying to conceive abstain from alcohol.