Four times, the authorities went after the famed Las Vegas sports gambler William T. Walters, and four times the man known as Billy emerged victorious.

But on Friday, Mr. Walters’s luck turned, as a federal jury in Manhattan convicted him on securities and wire fraud and conspiracy charges in one of the biggest insider trading trials in years.

The verdict came after jurors had deliberated for a little more than half a day.

“To say that I was surprised would be the understatement of my life,” Mr. Walters, 70, told reporters as he left the courtroom. “If I would have made a bet I would have lost. I just did lose the biggest bet of my life. Frankly I’m in total shock.”

His lawyer, Barry H. Berke, said he would appeal the verdict.

Mr. Walters was accused in the latest case of using nonpublic information from a board member of a Dallas-based dairy processing company, Dean Foods, to make more than $40 million from 2008 to 2014 by realizing profits and avoiding losses.

Prosecutors said that Mr. Walters had supplied the board member, Thomas C. Davis, with a prepaid cellphone called the Bat Phone to use when conveying secret information and to have sometimes spoken in code, referring to Dean Foods as “the Dallas Cowboys.”

“In engaging in his yearslong stock fraud scheme, Walters underestimated law enforcement’s resolve to pursue and catch those who cheat the market,” Joon H. Kim, the acting United States attorney in Manhattan, said in a statement.

The trial capped the most significant criminal insider trading case in Manhattan since one involving Rajat Gupta, a former McKinsey managing director and Goldman Sachs director who was convicted in 2012 of providing inside information to the billionaire hedge fund manager Raj Rajaratnam.

The investigation into Mr. Walters’s activities and his trial drew in prominent names from the worlds of finance and professional golf, shedding light on the way sports betting and Wall Street sometimes overlap.

Carl C. Icahn, the billionaire investor who is an unpaid adviser to President Trump, emerged in testimony and court filings as having had frequent discussions with Mr. Walters. A broker for Mr. Walters testified on cross-examination that some of Mr. Walter’s stock-trading ideas had come from Mr. Icahn, who was not charged with wrongdoing.

During a hearing outside the presence of the jury, one of Mr. Walters’s lawyers told the judge that Mr. Walters and Mr. Icahn were friends.

The lawyer, Paul Schoeman, added: “Mr. Walters has a long history of investing in stocks that Mr. Icahn has publicly announced he’s interested in.”

Phil Mickelson, the champion professional golfer, was also mentioned during the trial as someone who had traded in Dean Foods shares and once owed nearly $2 million in gambling debts to Mr. Walters.

Mr. Mickelson made roughly $1 million trading Dean Foods shares; he agreed to forfeit those profits in a related civil case brought by the Securities and Exchange Commission.

Mr. Mickelson, known as Lefty because of his left-handed stroke, was not charged with criminal wrongdoing. Though he was once seen as a potential witness at Mr. Walters’s criminal trial, he was never called to testify.

After three weeks of testimony, the jury began deliberating Mr. Walters’s fate just before 4 p.m. on Thursday. It reached its verdict by 2 p.m. on Friday.

Mr. Walters stood to face the jurors as they filed into a hushed courtroom in Federal District Court in Manhattan. He shook his head slightly as the jury forewoman uttered the word “guilty” in response to questions about each of the 10 counts.

After the jury was dismissed, Mr. Walters hugged his wife and Mr. Berke.