Larry Zacarese, an assistant police chief at Stony Brook University making his first run for office, pulled off a resounding upset victory over veteran state Sen. Phil Boyle (R-Bay Shore) in the Republican primary for Suffolk County sheriff Tuesday.

“This has been the epitome of an outsider grass-roots campaign against a big machine,” said Zacarese, 42, of Kings Park. “The voters spoke with an overwhelming message that they want a qualified candidate for sheriff.”

Boyle, 56, a three-term senator who was the Republicans’ designated candidate, still has the Conservative and Independence Party lines. He conceded the Republican line shortly after 10 p.m.

“I congratulate Larry,” Boyle said in an interview.

Boyle then added, “I’m still a candidate.” He declined to comment on the reasons for his defeat and would not say if he would seek the Democratic line.

Zacarese, an NYPD officer and sergeant before becoming assistant police chief eight years ago, had hammered Boyle for his lack of direct law enforcement experience.

advertisement | advertise on newsday

The sheriff runs the county jails in Riverhead and Yaphank with about 900 correction officers, and also oversees 250 sheriff’s deputies.

Sheriff Vincent DeMarco, a Conservative who has held the seat for the past 12 years, did not seek re-election after the Conservative Party backed Boyle, a 22-year state lawmaker.

DeMarco had angered party leadership by initiating a corruption investigation into Edward Walsh, a lieutenant at the jail and the county Conservative chairman. The probe led to federal charges against Walsh last year for collecting $200,000 in salary when he was golfing, gambling and politicking.

Walsh was convicted, and is scheduled to begin serving his two-year prison sentence next month. Boyle employs Walsh’s wife, Patricia, as a senate aide.

Democratic Party chairman Richard Schaffer before Tuesday night’s vote would not discount the possibility of giving Boyle the Democratic sheriff’s nomination.

The Democratic Party’s candidate, attorney and former Huntington town board member Stuart Besen, has yet to form a campaign committee with the state Board of Elections. Schaffer and Besen both have said Besen could be replaced as the Democratic candidate.

Boyle had spent the final weekend of the campaign in an unusual way: driving donated food, water and cleaning supplies to Houston, to aid victims of Hurricane Harvey.

He left for the 26-hour drive Thursday night at 8 o’clock and returned at 4 a.m. Monday as part of an eight-vehicle caravan of donated goods organized by Lloyd Harbor businessman George Schwertl.

“I know the people of Texas gave help to us after Hurricane Sandy, and I wanted to return the favor,” Boyle said. He said he made campaign phone calls when he wasn’t driving.

Zacarese, in their only debate, argued that, “a law enforcement background is crucial” for the sheriff’s job. He said employees of the office are looking for “a law enforcement leader” to take over.

advertisement | advertise on newsday

To counter such attacks, Boyle cited criminal justice legislation he helped pass that took aim at the heroin epidemic and MS-13 gang violence.

Zacarese and Boyle said they would keep politics out of the sheriff’s office, and make battling opioid abuse and gangs such as MS-13 priorities.

Boyle had the backing of the Suffolk Corrections Officers Association, the deputy sheriffs union and the Association of Municipal Employees, as well as the Suffolk County Police Benevolent Association.

Suffolk Republican chairman John Jay LaValle Tuesday night called for unity behind Zacarese. He noted that if Boyle won, it would open up the seat in the State Senate, where Republicans hold a tenuous majority.

“The Republican Senate majority, which protects Long Island taxpayers, is safer today than it was yesterday,” he said in a statement. “It’s time to unify behind our candidate and focus on eradicating the gang violence and heroin epidemic that is poisoning our children.”