Spurred by the election of Alexandria Ocasio-Cortez to Congress and Julia Salazar to the state Senate, the Democratic Socialists of America has become a potent political force to be reckoned with in New York City politics.

The far-left group was once seen as part of a fringe movement. But at least eight candidates for public advocate — considered a stepping stone to the mayoralty — have filled out the DSA’s 42-question questionnaire in a bid to win its endorsement in the special election to replace incoming state Attorney General-elect Letitia James, who currently holds the post.

In a special, nonpartisan election that will take place in the middle of winter and could include as many as a dozen candidates, a bloc of votes from committed Democratic socialists could determine the winner.

Among the candidates cozying up to the DSA are Brooklyn Councilmembers Jumaane Williams and Rafael Espinal, Assemblyman Daniel O’Donnell of Manhattan’s West Side and liberal activist and DSA member Nomiki Konst.

The candidates’ answers show they back nearly the entirety of the DSA’s leftist agenda, including: giving noncitizens the right to vote in municipal elections; supporting illegal strikes by government workers; allowing public funding for pro-Palestinian groups that support the boycott, divestment and sanctions [BDS] movement against Israel; a pledge to refuse campaign contributions from the real-estate industry; endorsing government-controlled “universal” rent control and health care; lessening criminal sentences for violent criminals; protecting sex workers; and providing free CUNY tuition for all.

James will become AG on Jan. 1, and Mayor de Blasio is expected to schedule the election for sometime in February.

Analysts said the surge in popularity for democratic socialism has been propelled by younger voters first inspired by the 2016 presidential candidacy of Bernie Sanders.

But it was Ocasio-Cortez’s stunning upset victory over veteran Queens-Bronx Rep. Joe Crowley in the June Democratic primary that provided clear evidence of the DSA’s growing clout in the Big Apple. She whipped Crowley, also the Queens Democratic Party chairman, in a 15-point landslide, thanks to a surge in young voters in neighborhoods like Astoria.

Salazar trounced veteran Brooklyn state Sen. Martin Dilan in gentrifying Williamsburg, Greenpoint and Bushwick.

“Everyone wants DSA’s endorsement. When they endorse a candidate, they go all out. They show up. They knock on doors,” said political consultant Rebecca Katz, who worked for Cynthia Nixon, a candidate for governor who was endorsed by the DSA. “DSA is growing in importance every year. They’re getting some wind.”

And the DSA holds its candidates accountable.

The group endorsed Williams for lieutenant governor earlier this year, but during a candidates’ meeting last week, a DSA questioner grilled him for taking tens of thousands of dollars in campaign donations from real-estate interests after vowing he would not, according to an audio recording of the meeting obtained by The Post.

A DSA leader said the gain in popularity is no fluke, and politicians who cater to the corporate class have been put on notice.

“DSA has definitely proven itself to be a force in NYC politics this year,” the group’s Sam Lewis said.

”We are going to stay focused on building grass-roots power this year, but more and more candidates are realizing they need to pick a side. You can’t stand with working people if you are bankrolled by the powerful and privileged.”