How do genes influence our sexuality? The question has long been fraught with controversy.

An ambitious new study — the largest ever to analyze the genetics of same-sex sexual behavior — found that genetics does play a role, responsible for perhaps a third of the influence on whether someone has same-sex sex. The influence comes not from one gene but many, each with a tiny effect — and the rest of the explanation includes social or environmental factors — making it impossible to use genes to predict someone’s sexuality.

“I hope that the science can be used to educate people a little bit more about how natural and normal same-sex behavior is,” said Benjamin Neale, a geneticist at the Broad Institute of M.I.T. and Harvard and one of the lead researchers on the international team. “It’s written into our genes and it’s part of our environment. This is part of our species and it’s part of who we are.”

The study of nearly half a million people, funded by the National Institutes of Health and other agencies , found differences in the genetic details of same-sex behavior in men and women. The research also suggests the genetics of same-sex sexual behavior shares some correlation with genes involved in some mental health issues and personality traits — although the authors said that overlap could simply reflect the stress of enduring societal prejudice.

Even before its publication Thursday in the journal Science, the study has generated debate and concern, including within the renowned Broad Institute itself. Several scientists who are part of the L.G.B.T.Q. community there said they were worried the findings could give ammunition to people who seek to use science to bolster biases and discrimination against gay people.