When transgender people undergo sex-reassignment surgery, the beneficial effect on their mental health is still evident — and increasing — years later, a Swedish study suggests.

Overall, people in the study with gender incongruence — that is, their biological gender doesn’t match the gender with which they identify — were six times more likely than people in the general population to visit a doctor for mood and anxiety disorders. They were also three times more likely to be prescribed antidepressants, and six times more likely to be hospitalized after a suicide attempt, researchers found.

But among trans people who had undergone gender-affirming surgery, the longer ago their surgery, the less likely they were to suffer anxiety, depression or suicidal behavior during the study period, researchers reported in The American Journal of Psychiatry.

Surgery to modify a person’s sex characteristics “is often the last and the most considered step in the treatment process for gender dysphoria,” according to the World Professional Association for Transgender Health.

Many transgender and gender-nonconforming individuals "find comfort with their gender identity, role, and expression without surgery," but for others, "surgery is essential and medically necessary to alleviate their gender dysphoria," according to the organization.

While the new study confirms that transgender individuals are more likely to use mental health treatments, it also shows that gender-affirming therapy might reduce this risk, coauthor Richard Branstrom of the Karolinska Institutet in Stockholm told Reuters Health by email.

Branstrom and colleague John Pachankis of the Yale School of Public Health in New Haven, Connecticut found that as of 2015, 2,679 people in Sweden had a diagnosis of gender incongruence, out of the total population of 9.7 million.

That year, 9.3 percent of people with gender incongruence visited a doctor for mood disorders, 7.4 percent saw a doctor for anxiety disorders and 29 percent were on antidepressants. In the general population, those percentages were 1 percent, 0.6 percent and 9.4 percent, respectively.

Just over 70 percent of people with gender incongruence were receiving feminizing or masculinizing hormones to modify outward sexual features such as breasts, body fat distribution and facial hair, and 48 percent had undergone gender-affirming surgery. Nearly all of those who had surgery also received hormone therapy.

The benefit of hormone treatment did not increase with time. But “increased time since last gender-affirming surgery was associated with fewer mental health treatments,” the authors report.

In fact, they note, “The likelihood of being treated for a mood or anxiety disorder was reduced by 8 percent for each year since the last gender-afﬁrming surgery,” for up to 10 years.

Transgender individuals’ use of mental health care still exceeded that of the general Swedish population, which the research team suggests is due at least partly to stigma, economic inequality and victimization.

“We need greater visibility and knowledge about challenges people are confronted with while breaking gender and identity norms,” Branstrom said.

Dr. Joshua Safer, executive director at Mount Sinai Center for Transgender Medicine and Surgery in New York City, told Reuters Health by email, “If anything, the study likely under-reports mental health benefits of medical and surgical care for transgender individuals.”

Safer, who was not involved in the study, said the fact that mental health continued to improve for years after surgery “suggests (surgery provides) extended and ongoing benefit to patients living according to gender identity.”

Follow NBC Out on Twitter, Facebook & Instagram