Teen suicide attempts in the U.S. declined after same-sex marriage became legal and the biggest impact was among gay, lesbian and bisexual kids, a study found.

The research found declines in states that passed laws allowing gays to marry before the Supreme Court made it legal nationwide. The results don't prove there's a connection, but researchers said policymakers should be aware of the measures' potential benefits for youth mental health.

Suicide is the second-leading cause of death for all U.S. teens. Suicidal behavior is much more common among gay, lesbian and bisexual kids and adults; about 29 percent of these teens in the study reported attempting suicide, compared with just 6 percent of straight teens.

Laws that have the greatest impact on gay adults may make gay kids feel "more hopeful for the future," said lead author Julia Raifman, a researcher at Johns Hopkins' Bloomberg School of Public Health.

Let our news meet your inbox. The news and stories that matters, delivered weekday mornings. This site is protected by recaptcha

The measures also could create more tolerance and less bullying, making these teens feel less stigmatized. Those effects could also benefit straight teens but more research is needed to determine how the laws might influence teen behavior, Raifman said.

The study was published Monday in JAMA Pediatrics .

The researchers analyzed data on more than 700,000 public high school students who participated in government surveys on risky youth behavior from 1999 through 2015, the year the Supreme Court legalized same-sex marriage.

About 230,000 students reported being gay, lesbian or bisexual. The surveys didn't ask about transgender status. They included questions about suicide attempts, smoking and alcohol or drug use.

In 32 states that enacted same-sex marriage laws during the study, suicide attempts dropped 7 percent among all students and 14 percent among gay kids after the laws were passed. There was no change in suicide attempts in states without those laws.

The study only included suicide attempts, not deaths.

The new work makes an important contribution to identifying how laws limiting gay rights may affect psychological and physical health, said Columbia University public health researcher Mark Hatzenbuehler.

But more research is needed to determine which teens are most vulnerable to policies that limit gay rights, he wrote in an accompanying editorial.

Follow NBC Out on Twitter, Facebook and Instagram.