Democrat Julie Lofstad defeated Republican Richard Yastrzemski in a Southampton Town special election Tuesday.

With all 42 electoral districts counted, Lofstad had 2,771 votes to Yastrzemski’s 1,721, according to preliminary results from the Suffolk County Board of Elections.

Lofstad will serve the two years left in the unfinished term of ex-Councilman Bradley Bender, who pleaded guilty to selling oxycodone pills and resigned Nov. 24.

Her victory means a Democratic-Independence alliance will continue to control the South Fork town, where the GOP dominated politics for decades until 2013.

Lofstad also had the backing of the Independence and Conservative parties in the special election. Yastrzemski had only the Republican line.

“We knew going in we had an uphill battle, but me and my team, we worked hard,” Yastrzemski said Tuesday night. “I thought it was two respectful races. She’s a good person and she’s got her work cut out for her.”

advertisement | advertise on newsday

Both Lofstad and Yastrzemski competed less than three months ago in the Nov. 3 general election.

Yastrzemski, a Southampton Village trustee, was the GOP candidate for town supervisor last year but lost to Independence Party member Jay Schneiderman.

Lofstad, a community activist from Hampton Bays, fell 115 votes short of winning a town board seat in a four-way race.

Democratic-leaning officials have had a three-person majority on the Southampton Town Board since 2013, when victories by former Supervisor Anna Throne-Holst, Democrat Bridget Fleming and Bender broke years of rule by Republicans and Conservatives.

Throne-Holst, an Independence Party member, left office at the end of 2015 to seek the Democratic nomination for Congress. Fleming was elected to the Suffolk legislature in November.

Schneiderman, the new supervisor, is an Independence Party member and former Suffolk legislator who ran alongside Democrats in November.

Also on the town board is Democrat John Bouvier and Republicans Christine Scalera and Stan Glinka.

During the campaigns in the fall and this winter, Lofstad stressed the importance of water quality, while Yastrzemski touted his management experience as a member of the Southampton Village Board since 2008.