Massachusetts State Lottery officials knew for years that a small group of gambling syndicates had virtually taken over a game called Cash WinFall — winning most of the prizes during high payoff periods — but did nothing about it until the Globe began investigating, according to state Inspector General Gregory W. Sullivan.

Sullivan’s report details the way a handful of math and science wizards, including Massachusetts Institute of Technology undergraduates looking for an interesting school project, turned Cash WinFall into a nearly fulltime business, spending $40 million on tickets over a seven-year period and winning an estimated $48 million.

And lottery officials were happy about the huge sales to these sophisticated gamblers, bending and breaking lottery rules to allow them to buy hundreds of thousands of the $2 tickets, Sullivan found. If anything, lottery officials were envious, with one supervisor asking in an e-mail: “How do I become part of the club when I retire?”

State Treasurer Steven Grossman, who oversees the lottery, finally stopped the game this year. On Monday, Grossman said the agency should have taken action sooner.

“I feel it is important to essentially apologize to the public because a game was created that allowed syndicates to gain special opportunities that others did not have — using machines themselves, partnership with lottery agents, using them after hours. We’re sorry some gained unfair advantage,” said Grossman, who had requested Sullivan’s investigation.

“Revenues were tremendous and the lottery benefited, but there were practices that were not appropriate and things done that were not rignt,” he said.

However, the inspector general recommended no further action, concluding that lottery officials got no personal benefit from the syndicates’ manipulations. He also found that ordinary gamblers still had a fair chance at winning Cash WinFall, though the syndicates reported a much higher rate of profit than ordinary gamblers.

Sullivan found that the lottery failed to manage the game or enforce the rules, but concluded the game was “a financial success for the lottery.”

The Globe reported last summer that a few gamblers with an extraordinary knowledge of math and probability had found a quirk in Cash WinFall shortly after it was introduced in 2004, allowing them to make an almost guaranteed profit as long as they purchased enough tickets at the right time. They figured out that, for a few days every three months or so, Cash WinFall became the most reliably lucrative lottery game in the country.

Sullivan said that these high rollers made a livelihood from playing it, giving up their day jobs to devote nearly full-time to the game, often backed by hundreds of thousands of dollars put up by investors.