Last week, millions of Americans weree navigating crushing crowds and spending hours traveling in order to catch a glimpse of Pope Francis on his first visit to this country. To those who are devoutly religious, the pope's U.S. trip presents a unique opportunity to get papal blessings, receive mercy and feel closer to God.

But even those devoted Catholics who aren’t in the front row seat for Francis' visit may see benefits to their belief. A slew of research has tied being religious with better well-being and overall mental health. A number of studies have found that devout people have fewer symptoms of depression and anxiety, as well as a better ability to cope with stress. Certain religious practices may even change the brain in a way that boosts mental health, studies suggest.

However, religion could also be a double-edged sword: Negative religious beliefs — for example, that God is punishing or abandoning you — have been linked with harmful outcomes, including higher rates of depression and lower quality of life.

"If people have a loving, kind perception of God," and feel God is supportive, they seem to experience benefits, said Kenneth Pargament, a professor of psychology and an expert on religion and health at Bowling Green State University in Ohio. But "we know that there's a darker side to spirituality," Pargament said. "If you tend to see God as punitive, threatening or unreliable, then that's not very helpful" to your health, he said. [8 Ways Religion Impacts Your Life]

Religion's mental health benefits

More On This...

A large body of research — particularly among people in the United States — has tied religious beliefs with positive outcomes for mental health. For example, a 2005 study of older adults in the San Francisco Bay area found that being religious served as a buffer against depression among people in poorer health, with the highest levels of depression among those who were in poor health and not religious. In addition, a 2013 study found that patients who are being treated for mental-health issues such as depression or anxiety responded better to treatment if they believed in God.

In another review of 93 studies on religion and health, Dr. Harold G. Koenig, director of the Center for Spirituality, Theology and Health at Duke University Medical Center, found that more religious people had fewer depressive symptoms.

"People who are more involved in religious practices and who are more religiously committed seem to cope better with stress," Koenig said. "One of the reasons is because [religion] gives people a sense of purpose and meaning in life, and that helps them to make sense of negative things that happen to them," Koenig said. A person's religious community can also provide support and encouragement through hard times, he said.

Religion and the brain

Studies on the brains of religious people may also provide an explanation for the link between religion and mental-health benefits, said Dr. Andrew Newberg, a neuroscientist at Thomas Jefferson University and Hospital in Philadelphia. Studies suggest that meditation, and meditative prayer (such as prayer that repeats a particular phrase), activate areas of the brain involved in regulating emotional responses, including the frontal lobes, Newberg said.

A 2010 study by Newberg and colleagues that included brain scans of Tibetan Buddhist and Franciscan nuns found that these long-term meditators had more activity in frontal-lobe areas such as the prefrontal cortex, compared with people who were not long-term meditators.

Strengthening these areas of the brain may help people be "more calm, less reactionary, better able to deal with stressors," Newberg said. However, these studies can't say that prayer changed the brain — it's possible that these differences existed before the meditators took up their prayer practice. [Mind Games: 7 Reasons You Should Meditate]

It's also possible that the beliefs and teachings advocated by a religion — like forgiveness, love and compassion — may "become integrated into the way the brain works," Newberg said. The more that certain neural connections in the brain are used, the stronger they become, he said, so if a religion advocates compassion, the neural circuits involved in thinking about compassion become stronger.

"So you keep coming back to these positive feelings and emotions, and that reduces stress, anxiety, and can lead to reduction in stress hormones," Newberg said.

Some religions also advocate that members stay away from high-risk health behaviors, such as smoking, drinking alcohol or overindulging in food. Steering away from these unhealthy behaviors could also be beneficial for brain function, he said.

Downsides for the devout

However, religion doesn't always have a positive effect on mental health — its impact depends on a person's beliefs, and whether religion is generally accepted by the larger community, experts said.

For example, if instead of advocating love and compassion, a religion advocates hate of nonbelievers, these negative beliefs would also become part of the way the brain works, Newberg said. In theory, this would turn on areas of the brain involved in thinking about hate, and could increase stress and stimulate the release of stress hormones, Newberg said.

In addition, if some people believe that a health condition — such as addiction — is a punishment from God, they may be less likely to seek treatment, Newberg said.

Pargament has also found that when people believe that God has abandoned them, or when they question God's love for them, they tend to experience greater emotional distress, and even face an increased risk ofan earlier death.

"These kinds of struggles have to do with the aspects of life that you hold sacred," Pargament said. "When you get shaken to that level, then … it's going to be very distressing."

Exactly why some people take a positive view of religion while others take a negative one is not known, and more studies should be conducted to examine this topic, Newberg said.

Pargament said some people can come out of a religious struggle feeling more whole, particularly those who have support from the community throughout their struggle. 

Copyright 2015 LiveScience, a Purch company. All rights reserved. This material may not be published, broadcast, rewritten or redistributed.