The crowd cheers as Republican Bob Turner appears on stage during an election night party.AP

Republicans have scored an upset victory in a House race that started as a contest to replace Rep. Anthony Weiner after he resigned in a sexting scandal but became a referendum on President Barack Obama’s economic policies.

Retired media executive and political novice Bob Turner defeated Democratic state Assemblyman David Weprin on Tuesday in the special election to fill the seat vacated by Weiner, a seven-term Democrat who resigned in June.

With more than 80 percent of precincts reporting, Turner had 54 percent of the vote to Weprin’s 46 percent in unofficial results.

“We’ve been asked by the people of this district to send a message to Washington,” Turner told supporters after the landmark win. “I hope they hear it loud and clear. We’ve been told this is a referendum. Mr. President, we are on the wrong track. We have had it with an irresponsible fiscal policy which endangers the entire economy.”

Weprin did not immediately concede.

The heavily Democratic district, which spans parts of Queens and Brooklyn, had never sent a Republican to the House. But frustration with the continued weak national economy gave Republicans the edge.

Turner has vowed to bring business practicality to Washington and push back on spending and taxes.

The race was supposed to be an easy win for Democrats, who have a 3-1 ratio registration advantage in the district.

Weprin, a 56-year-old Orthodox Jew and member of a prominent Queens political family, seemed a good fit for the largely white, working-class district, which is nearly 40 percent Jewish.

But voter frustration with Obama put Weprin in the unlikely spot of playing defense. A Siena Poll released Friday found just 43 percent of likely voters approved of the president’s job performance, while 54 percent said they disapproved. Among independents, just 29 percent said they approved of Obama’s job performance.

Turner, a 70-year-old Catholic, vowed to push back on Obama’s policies if elected. He received help from prominent Republicans including former Mayor Rudy Giuliani, whose much-praised stewardship of the city after the Sept. 11, 2001, terror attacks was recalled during the 10th anniversary of the attacks last weekend.

Weprin became embroiled in New York-centric disputes over Israel and gay marriage, which cost him some support among Jewish voters.

Orthodox Jews, who tend to be conservative on social issues, expressed anger over Weprin’s vote in the Assembly to legalize gay marriage. In July, New York became one of six states to recognize same-sex nuptials.

Former Mayor Ed Koch, a Democrat, endorsed Turner in July as a way to “send a message” to Obama on his policies toward Israel. And Weprin was challenged on his support of a proposed Islamic center and mosque near the World Trade Center site, in lower Manhattan.

The Democratic Party enlisted two of its biggest guns, former President Bill Clinton and Gov. Andrew Cuomo, to record phone calls for Weprin. And Democrats relied on organized labor and other affiliated groups to bring voters to the polls.

The House seat opened up when Weiner was pushed by party leaders to resign after sending sexually provocative tweets and text messages to women he met online.

The trouble for Weiner, who served seven terms, began when a photo of a man’s crotch surfaced on his Twitter feed. He initially denied the photo was of him but later admitted it was.

Weiner, who’s married, resigned June 16 after two weeks of fighting off pressure to step aside. He apologized for “the embarrassment that I have caused” and said he hoped to continue to fight for the causes dear to his constituents.

In a special election in May, Democrat Kathy Hochul won a heavily Republican upstate district after pledging to protect Medicare, the popular government health care plan for seniors.

The state replaced outdated lever-operated voting machines last year in favor of paper ballots and optical scanners, which take more time to close and process. Polls closed at 9 p.m. Tuesday, and results trickled in slowly, but a Board of Elections spokeswoman said the vote-tallying system ran smoothly and there were no problems to report.