The winner of the Republican primary for Smithtown Town supervisor remained unclear Wednesday, with hundreds of absentee and affidavit ballots yet to be counted in a white-knuckle race between longtime incumbent Patrick Vecchio and Councilman Ed Wehrheim.

Wehrheim had a 39-vote lead in the unofficial machine-counted results, but at least 357 absentee ballots and an unknown number of affidavit votes were still outstanding, said Nick LaLota, Republican commissioner of the Suffolk County Board of Elections. Those votes are scheduled to be counted Sept. 25.

The unofficial count Wednesday was 2,822 votes for Wehrheim and 2,783 for Vecchio. In a town with a largely Republican electorate, the GOP primary could determine the next supervisor.

Broken down by election district, the unofficial results showed Wehrheim’s strongest support near Nesconset, St. James and Kings Park. Vecchio carried much of Fort Salonga, Commack, Hauppauge and the villages.

“I never thought it would be this close,” Vecchio said.

At a banquet hall at Watermill Caterers in Smithtown on Tuesday night, the supervisor apologized to supporters for failing to bring them a win.

advertisement | advertise on newsday

They would have none of it.

“You’re still in it, kid,” a well-wisher told the 86-year-old Vecchio, who has held the office continuously since 1978, a record in New York State.

Both candidates were back at work at Town Hall on Wednesday morning.

Wehrheim, a former town Parks, Buildings and Grounds employee who rose to direct the department and is in the middle of his term as councilman, said he had gone to bed Tuesday night “feeling like a winner.”

“I was up against a 40-year-incumbent,” he said. “I don’t think anybody in these past elections has come close to matching him in a vote total.”

He said his call for renewal of town recreation facilities, business districts and roads and sidewalks had resonated with voters.

A similar message appeared not to have paid off for his running mates Bob Doyle and Tom Lohmann in the town council race, where incumbents and Vecchio allies Tom McCarthy and Lynne Nowick held leads of hundreds of votes each in the unofficial vote count.

Incumbent clerk Vincent Puleo, who ran with Wehrheim, was ahead of challenger Conrad Chayes, a Vecchio ally, in early vote totals.

The council results could have far-reaching implications in Smithtown politics, veteran Republican lobbyist Des Ryan said Wednesday, weakening the position of town GOP leadership that supported Wehrheim and his insurgent ticket.

Also, should Wehrheim win the supervisor’s job and vacate his council seat in January, the town board would jointly appoint someone to fill the vacated seat.

advertisement | advertise on newsday

“They are going to have to compromise on candidates who are acceptable to both camps,” Ryan said.

Ryan, who has criticized Vecchio in the past, said the vote totals — higher for McCarthy and Nowick than for Vecchio — signaled voter disenchantment with the supervisor.

Town government has been slow to adopt policies for transit-oriented development that are popular elsewhere on Long Island, he said, and infrastructure is “gradually deteriorating.”

But Vecchio was adamant about the strength of his governing record, which he said includes successive no-tax-increase budgets, “a triple-A bond rating, $17 million in reserve funds, $40 million” from state and county government toward sewers in Kings Park and Smithtown.

Forty years of relationship-building brought that money, which could transform the town, he said. “You will see things change,” he said.

advertisement | advertise on newsday

Vecchio’s first bid for supervisor — he won as a Democrat in 1977 — was every bit as close as this one appears to be. Speaking about that race earlier this year, Vecchio put his margin of victory in that race at 67 votes and told stories about how he fought — and ultimately broke — the Republican machine that then controlled the town.

He was more somber Wednesday.

“Maybe I’ve been here too long,” he said. “Maybe people got tired of me.”