Hillary Clinton and Bernie Sanders are locked in a surprisingly competitive battle for New York, with a poll on Thursday showing that the Vermont senator has closed to within 12 points of the former first lady — who only recently led by 48 in her adopted home state.

The Quinnipiac University poll shows Clinton leading 54 to 42 percent heading into the New York primary on April 19, when 291 delegates are at stake.

That’s a dramatic shift from two polls earlier in March — an Emerson College survey that showed Clinton crushing Sanders 71-23 and a Siena College poll with her ahead 55-34.

Clinton is running very strongly with women and African-American voters, but white voters are split — 48 percent for Clinton, 47 percent for Sanders.

Democratic analyst Douglas Schoen said the closer-than-expected results mirror a national trend.

Sanders, he said, is connecting with the most liberal progressive voters, of whom there are many in New York. Bernie is also riding momentum from a wave of victories in Western states.

“There’s a segment of the Democratic primary vote in New York who are to the left of Hillary Clinton,” said Schoen, who helped run her 2000 Senate campaign and Bill Clinton’s presidential campaigns.

“This will be a competitive race, but Hillary will win,” he predicted.

If Clinton comes out on top in a close contest, however, Sanders would still pick up a significant share of delegates.

Sanders’ boosters in the Working Families Party said the poll shows he has a real shot at an upset.

“Bernie has huge momentum and the gap is closing. We’ve seen momentum across all demographics,” said the party’s state director, Bill Lipton.

The Brooklyn-born Sanders began his New York primary push Thursday night at a rally before thousands in the South Bronx, where he attacked Clinton for her ties to Wall Street and made an appeal to the black and Hispanic voters he needs to win.

Sanders homed in on the economy, “Wall Street crooks” and immigration in his 40-minute address and continued his demand for Clinton to release transcripts of speeches she delivered for $250,000 a pop to Wall Street execs.

“If you’re going to get paid $250,000 for a speech, it must be a brilliant speech. It must be an Earth-shattering speech written in Shakespearean prose,” he said to thunderous applause.

Clinton is preparing to spend far more time and cash in New York than she originally had budgeted, according to people close to the campaign, underscoring how concerned she is.

In an appearance Thursday at SUNY Purchase in Westchester, Clinton lambasted GOP rival Donald Trump and dueled with pro-Sanders hecklers.

“Just yesterday, Donald Trump said women should be punished for having abortions,” Clinton said as the crowd booed.

The former secretary of state got fired up after hecklers shouted, “She wins, we lose!”

“We’re very sorry you’re leaving!” Clinton declared as the demonstrators were escorted out.

Where does Clinton actually stand on the issues? It depends on when she’s answering: