(CNN) Children born to women who had a severe infection during pregnancy, such as sepsis, flu or pneumonia, show an increased risk of autism spectrum disorder and depression, new research finds. Yet those exposed to even a relatively minor urinary tract infection in utero also experienced an increased risk of such disorders.

Women should "make sure you have your influenza vaccination in pregnancy," said Dr. Kristina Adams Waldorf , co-author of the study and a professor of obstetrics and gynecology at the University of Washington School of Medicine in Seattle.

Although the flu shot is safe for pregnant women, coming down with the illness during pregnancy "can be very dangerous for your baby's mental health and brain development," she said.

Autism and depression, not bipolar disorder

Adams Waldorf and her colleagues analyzed patient data from Sweden's national health registry, specifically looking at information "for the entire population of pregnant women that were hospitalized between 1973 and 2014," she said. "And then we had up to 41 years of follow-up on those children that stayed in Sweden."

In total, they looked at the records of 1,791,520 children and, using hospitalization codes, identified those who'd been exposed to their mother's infection in utero.

The study was published Wednesday in the journal JAMA Psychiatry. The results, Adams Waldorf said, were "very surprising."

Children born to mothers with an infection during pregnancy had a 79% increased risk of an autism diagnosis and a 24% increased risk of a depression diagnosis as adults, the researchers found. They also saw "an increased risk of suicide in those children that had been exposed to infections in utero," Adams Waldorf said, adding that this association made the depression findings "much stronger."

The increased risk level for autism and depression was detected regardless of whether fetal exposure was to a severe infection -- such as sepsis, flu, pneumonia, meningitis or encephalitis, chorioamnionitis (an infection of the placental tissues) or pyelonephritis (a severe kidney infection) -- or a urinary tract infection.

No increased risk of bipolar disorder or psychosis, including schizophrenia, was seen among those exposed to infection during fetal development, the study showed.

"We need more research into understanding the inflammation that occurs in the urinary tract infection and how it might impact the fetus," Adams Waldorf said. More research is also needed on areas of the fetal brain that are extremely vulnerable to damage from infection and inflammation.

"The hippocampus is a very vulnerable part of the brain that is targeted by Zika virus infection but may be vulnerable to other infections as well," she said, explaining that this brain region "plays a key role in social and emotional functioning."

Sensitive periods in brain development

Margaret McCarthy, a neuroscientist and professor at the University of Maryland School of Medicine, said the study is "astonishing" in terms of both the number of subjects and the length of time. "To my knowledge, this is the largest and most comprehensive study of in utero infections and the health outcomes for the offspring," said McCarthy, who had no role in the new research.

The fact that both severe infection and urinary tract infection conferred the same level of risk "highlights that there's something very subtle that can be very profound in brain development, and it probably has to do with sensitive periods in brain development that we don't understand yet," she said.

In her own research on sex differences and brain development, she found that a lot of immune system signaling "sculpts" the male brain during development. "And we have speculated that this increases their risk for neurodevelopmental or neuropsychiatric disorders like ADHD, autism, et cetera." Yet, she added, studies have shown that both boosting inflammatory molecules (due to an illness or infection) or dampening them all the way down (by treating an illness or infection with certain medicines) may have deleterious effects on brain development.

"Brain development is really complicated, and things that we think are relatively benign sometimes aren't, because we still don't understand just a lot of the basic signaling molecules that are involved," she said.

Dr. Alan S. Brown , a professor of psychiatry and epidemiology at the Columbia University Medical Center, said in an email that "overall, the investigators have done a commendable job." However, he also noted that the "findings could also be influenced by treatment-seeking behaviors."

A previous study from Taiwan showed that treatment for infection in the third trimester was related to autism risk, explained Brown, who was not involved in the new study.

Get CNN Health's weekly newsletter Sign up here to get The Results Are In with Dr. Sanjay Gupta every Tuesday from the CNN Health team.

"Starting in the 1990s, we demonstrated that prenatal exposure to several pathogens including rubella, influenza and toxoplasmosis are related to risk of schizophrenia," he said of his own research. "In more recent work, we showed that prenatal influenza was related to bipolar disorder."

Brown believes the new study provides more evidence for "relationships between prenatal infection and autism and opens up a potential new avenue of exploration regarding prenatal infection and depression."

McCarthy said, "I don't think pregnant women should panic. Try to avoid any kind of infection; avoid it if you can, and if you do have to treat it, treat it judiciously."