People taking the wildly popular drugs Ozempic, to treat diabetes, and Wegovy, to combat obesity, are slightly less likely to have suicidal thoughts who are not taking them, researchers reported on Friday.

Millions of people take Ozempic and Wegovy, which are considered to be among the biggest blockbusters in medical history. But last year a European drug safety agency said it was investigating whether the drugs cause suicidal thoughts. The new study, published in the journal Nature Medicine, was funded by the National Institutes of Health and used a huge population. The findings provide data that may potentially reassure people who take the drugs.

Novo Nordisk, maker of the drugs, had no role in the study, and the study’s investigators had no conflicts of interest.

The investigators used anonymized electronic health records from a database of 100.8 million people. That allowed them to look at two groups: 240,618 who were prescribed Wegovy or other weight loss drugs, and 1,589,855 who were prescribed Ozempic or other medicines to lower their blood sugar. Suicidal thoughts were included in patients’ records as part of routine monitoring of their health.

The investigators compared the incidence of suicidal thoughts in people who were taking the drugs with the incidence among similar people who were not taking them but were taking other weight loss and anti-diabetes medications. They also asked if there was an increase in the recurrence of suicidal thoughts among those taking the drugs who had previously reported thoughts of suicide.

The database’s size allowed the researchers to look at subgroups such as sex, race and age groups.

“No matter how hard we tried we did not see any increased risk,” said Rong Xu, director of the Center for Artificial Intelligence in Drug Discovery at Case Western Reserve University in Cleveland.

Dr. Xu conceived the study and interpreted the data with Dr. Nora D. Volkow, director of the National Institute on Drug Abuse.

But it was an observational study, so it is impossible to draw conclusions about cause and effect. Such studies can only show associations. “More studies are absolutely needed,” Dr. Volkow said.

Dr. Xu, Dr. Volkow and their colleagues decided to pursue the research last year. A committee of the European Medicines Agency, a group that evaluates and monitors the safety of drugs, announced in July that it was investigating reports from Iceland that some patients taking Ozempic or Wegovy had said that they were thinking of killing themselves or were deliberately injuring themselves. The agency said it had found and was analyzing about 150 such cases.

Dr. Volkow said suicide risk was possible with the drugs because “other anti-obesity treatments that looked promising and were investigated in the past were discontinued due to the risk of suicidal behaviors.” One example was rimonabant, a drug that was withdrawn before it was ever sold in the United States.

During clinical trials of Ozempic and Wegovy by Novo Nordisk, no links were observed to suicidal thoughts. Those trials, though, were not designed to pick up rare adverse events that might occur when drugs are widely used.

But the case reports like the ones the European agency relied on are difficult to interpret. Were people having thoughts because of the drugs? Or were they having those thoughts for reasons that had nothing to do with the drugs? Dr. Volkow said she did not think the anecdotal reports alone proved the suicide risk, and the European agency recognized the limitations of its case reports when it started its investigation.

Monika Benstetter, a spokeswoman for the European agency, wrote in an email that the safety committee “has identified some issues that need further clarification and has issued new lists of questions to be addressed by the companies.” She added that the agency’s safety committee would address the issue at a meeting in April.

A U.S. Food and Drug Administration spokeswoman said that while the agency was continuing to monitor the drugs, it still found “that the benefits of these medications outweigh their risks when they are used according to the FDA approved labeling.”

Ambre James-Brown, a Novo Nordisk spokeswoman, said, “the findings in the study support the safety data collected from large clinical trial programs and post-marketing surveillance.”

Dr. Xu and Dr. Volkow’s research group has completed another study using the same huge database, asking whether Ozempic and Wegovy reduce cravings for cigarettes and alcohol. That study is under review at a journal, Dr. Xu said, adding that the group found that, in this case, anecdotal reports were correct. Those taking the drugs do, in fact, report less interest in drinking and smoking.