Gov. Phil Murphy narrowly survived a strong Republican challenge to win reelection in New Jersey, becoming the state’s first Democratic governor in four decades to earn a second term.

With 99% of the state’s more than 2.4 million votes tallied, Murphy was ahead of Republican Jack Ciattarelli by about 1.5 percentage points Thursday morning, after the Associated Press projected Murphy as the winner late Wednesday.

Ciattarelli, however, did not concede.

“With the candidates separated by a fraction of a percent out of 2.4 million ballots cast, it’s irresponsible of the media to make this call when the New Jersey secretary of state doesn’t even know how many ballots are left to be counted,” said Stami Williams, Ciattarelli’s campaign spokesperson.

Late Wednesday night, Murphy, joined by his wife, Tammy, and their four children, took the stage in Asbury Park to thank his supporters and he promised to continue the policies popular among Democrats that he pursued during his first four years in office.

Murphy did not back away from the restrictions he implemented during the pandemic that angered and energized his opponents, saying the state is recovering “by following science.”

In a possible reference to the closeness of the race but without elaborating, he said he would represent all New Jerseyans, “whether you voted for me or not.”

Ciattarelli had no public appearances.

Despite polls suggesting an easy win for Murphy, Ciattarelli nearly pulled off an upset after running a focused campaign in which he managed to keep some distance from former President Donald Trump without alienating Trump’s most hard-core supporters. In the end, though, Murphy held on even as a Republican won in the nation’s only other gubernatorial race, in Virginia.

Murphy also had to face changes in the national mood. A recent poll found that only 43% of New Jersey voters approved of the performance of President Joe Biden, a sharp skid from Biden’s previous standing in a state that voted for him heavily in 2020.

A former Goldman Sachs executive, Murphy, 64, first was elected governor in 2017 as a mild-mannered alternative to former Republican Gov. Chris Christie and then-President Trump, while also trumpeting his liberal bona fides.

He delivered on his progressive top-ticket items: legalizing marijuana, hiking the minimum wage to $15 an hour over time, and doubling paid family leave. During his first term, New Jersey also passed a tax on millionaires and forged ahead on police reform.

But the tidal shifts of the last four years — between the onslaught of the pandemic and upheavals in national politics — presented new challenges for Murphy on the campaign trail.

A former assemblyman from Somerset County with a moderate record, Ciattarelli, 59, cast Murphy as a wealthy liberal who was out of touch with everyday New Jerseyans. The Republican homed in on perennial economic issues like the cost of living and sky-high property taxes. He also hammered Murphy’s vaccine and mask mandates as too restrictive, while blaming his pandemic response for gutting the economy.

Murphy was battling history in the race: No incumbent Democratic governor had won reelection in New Jersey since 1977. At the same time, he was a well-funded incumbent running in a state whose trajectory many viewed as swinging to the left, buoyed by a diversifying population.

Registered Democrats now outnumber Republicans by more than a million in New Jersey. The state rejected Trump by a 16 percentage point margin last year. Some polls showed Murphy cakewalking to victory by a double-digit margin, aided by low turnout in an off-year election.

But the voters made him sweat. The lead switched back and forth several times as counting continued for more than 22 hours after the polls closed at 8 p.m. Tuesday.

After almost two years of campaigning, Ciattarelli appeared to be gaining ground in recent weeks. Another survey found that after months in which voters listed COVID-19 as a top concern, they began citing taxes, schools, and the economy as key issues.

New Jersey does not have an automatic recount law in the event of close races, but candidates can request them in specific counties. Any political party seeking a recount must file for one in state Superior Court within 17 days of Election Day.

Murphy may face a dramatically different legislature. In an apparent down-ballot upset, New Jersey Senate President Steve Sweeney was on the verge of losing his seat to a virtually unknown Republican challenger, a conservative truck driver for the furniture store Raymour & Flanigan who estimates he spent less than $10,000 on the race.

Voting across the country sent shock waves to national Democrats, especially the loss in Virginia to another gubernatorial GOP candidate who kept some distance from Trump. In the Garden State, Murphy had tried to define Ciattarelli as a quiet ally of Trump, but the Republican seemed able to shake off that label.

The final weeks of the race saw attacks flying between the candidates. Outside spending spiked to almost $40 million — more than double the amount from four years ago. Murphy made appearances with top party leaders to get out the vote, including Biden, former President Barack Obama, and Sen. Bernie Sanders.

In Tuesday’s race, Murphy got a similar number of votes — 1.2 million — as when he won by double digits four years ago. But Ciattarelli got about 300,000 more votes than the previous GOP nominee.

Still, while Ciattarelli’s backers were perhaps more enthused about the race, many of Murphy’s policies and legislative achievements have been popular among New Jerseyans.

Staff writers Laura McCrystal, Jonathan Lai, and Ellie Rushing contributed to this article.