Democratic Assemb. Todd Kaminsky held a narrow lead Tuesday night over Republican Christopher McGrath in the special election to replace former Senate Majority Leader Dean Skelos — with control of the Senate potentially in the balance.

With all precincts in Nassau’s 9th Senate District reporting, Kaminsky led by just 780 votes, garnering 49.9 percent of the vote to McGrath’s 48.8 percent. Green Party candidate Laurence Hirsh got 1.1 percent.

County Board of Elections officials said there are more than 2,700 absentee ballots still outstanding, including 1,318 from Democrats, 1,169 from Republicans, 26 from Conservative Party members and 206 from voters unaffiliated with any major party.

See alsoSee latest 9th Senate District resultsStoryClinton 'deeply, deeply grateful' for NY winStoryTrump on win: 'It's impossible to catch us'

After 11 p.m., Kaminsky declared victory.

“When we started this campaign I promised I would fight as hard as I could. We would not stand for putting special interests ahead of Long Island interests,” Kaminsky said. “We sent a message to the special interests and the smoke-filled backrooms: We will not take it anymore.”

But McGrath was not ready to concede. “This race is too close to call it will not be decided tonight,” his campaign said. “All the votes will have to be counted in the coming days.”

advertisement | advertise on newsday

David Gugerty, Nassau’s Democratic Board of Elections commissioner, said early Wednesday he will go to court in the morning to begin the process of certifying the results.

Gugerty said a long, protracted legal fight over the election results would be a waste of time.

“There is no other plausible result from the election other than what we saw tonight,” he said.

GOP officials said McGrath won West Hempstead, Island Park, Point Lookout, Inwood, Lawrence, Cedarhurst, Lynbrook and Rockville Centre.

Democratic officials, meanwhile, said Kaminsky won big in the party’s strongholds in Elmont, Valley Stream and Long Beach.

During the past two months, the candidates crisscrossed the county touting their credentials and leveling sharp personal attacks at one another as they sought the vacant seat.

Kaminsky, 38, a former federal prosecutor from Long Beach, has cast himself as an ethical reformer and the antidote to the corruption plaguing Albany politics.

McGrath, 57, a personal injury attorney from Hewlett and first-time political candidate, focused on keeping the Senate in GOP control, arguing that a Democratic win would allow New York City Mayor Bill de Blasio to siphon school and tax aid from Long Island.

advertisement | advertise on newsday

Republicans hold 31 of the 63 Senate seats but control the chamber because of a governing coalition with six breakaway Democrats.

The winner of the special election will hold the seat until November when all Senate and Assembly seats are up.

Hirsh, 56, an accountant from Valley Stream, wants to end a state Board of Elections policy of allowing Democratic and Republican candidates to run on minor party lines.

A Siena College poll released on Saturday showed McGrath with an 8-point lead over Kaminsky, with 5 percent of voters undecided. A Siena poll taken a month earlier had Kaminsky, a first-term assemblyman, up by 2 points.

Democrats outnumber Republicans in the Senate district by roughly 20,000 registered voters with more than 52,000 voters unaffiliated with either party.

advertisement | advertise on newsday

With more than $3.2 million in combined spending, the race has been among the most expensive special elections in recent memory. McGrath’s campaign spent $857,000, while Kaminsky reported more than $845,000 in expenditures, records show.

In addition, a political action committee formed by StudentsFirst, a nonprofit that supports charter schools, spent nearly $1.5 million on TV ads and polling against Kaminsky. Teachers for Todd, a United Federation of Teachers PAC, spent $70,000 in the race’s final days supporting Kaminsky.

The candidates rolled out major endorsements in the race’s final days with President Barack Obama recording a robocall for Kaminsky, citing his support for raising the minimum wage and providing paid family leave for all New Yorkers. The powerful labor union, 1199 SEIU, endorsed McGrath, noting his legal work supporting Sept. 11 first responders.

Skelos was convicted with his son, Adam, in December on eight federal counts of bribery, extortion and conspiracy. They are appealing.

With John Asbury