Democrat Christine Pellegrino defeated Conservative Tom Gargiulo on Tuesday in the 9th Assembly District special election as the progressive and union-backed candidate pulled off an upset victory for the heavily Republican seat.

“This is a thunderbolt of resistance,” said Pellegrino, who becomes the first Democrat to hold the Assembly seat. “This is for all the supporters and voters who understand a strong progressive agenda is the way forward in New York.”

With all precincts reporting, Pellegrino won 58 percent of the vote to Gargiulo’s 42 percent, according to Suffolk and Nassau boards of election results posted Tuesday night.

The liberal wing of the Democratic Party and Working Families Party had invested heavily in the seat left vacant when Assemb. Joseph Saladino was appointed Oyster Bay supervisor. President Donald Trump had won the district with 60 percent of the vote.

The state teachers union funneled $200,000 to a committee backing Pellegrino, 48, a Baldwin teacher from West Islip active in the anti-Common Core “opt out” movement. She served as a Democratic National Convention delegate for U.S. Sen. Bernie Sanders (I-Vt.).

While Republicans hold a 13-point registration advantage in the district, progressive activists hoped to capitalize on opposition to Trump by turning out motivated Democrats in the election, Long Island’s first since November.

Sign up to receive The 1600 Get our inside look at the White House and goings on in the Donald Trump administration. By clicking Sign up, you agree to our privacy policy.

The win will have little bearing on the makeup of the Assembly, where Democrats hold a comfortable majority, but progressive leaders believed it was a harbinger of a Democratic wave.

“Bold populism that puts working families’ issues front and center. This is how we win in Trump country,” said Bill Lipton, state director of the Working Families Party, Tuesday night. “This is the lesson for Democrats around the country.”

Suffolk Conservatives had pushed for Gargiulo’s nomination. He would have become the only member of the party serving in the State Legislature.

Gargiulo wished Pellegrino luck in representing the district.

“We worked hard. I don’t know what happened,” he said.

Typically, Democrats would hardly compete in the 9th, a horseshoe-shaped district on the Nassau-Suffolk county line that includes Massapequa, West Babylon, Babylon Village, West Islip and West Bay Shore.

But Democrats say that in a low-turnout special election with progressives and union members galvanized by opposition to Trump, they had hope.

Teachers for Christine, formed by the New York State United Teachers, has spent $145,000 from May 10 to 17.

The GOP Assembly caucus and Conservative leadership had also sent supporters into the district to draw out voters.

County Executive Steve Bellone had also campaigned for Pellegrino, contributing the maximum of $4,400 to her campaign and knocking on doors for her. Suffolk Democratic Chairman Richard Schaffer, who is courting Conservative support in other races, stayed neutral in the race because of a past contribution from NYSUT to a Democratic state senate candidate that he said is under investigation.