SAN JOSE — San Jose Councilman Ash Kalra appeared Wednesday to pull off an upset win over rival Madison Nguyen who was deemed the front-runner in a hotly-contested race for the state’s 27th Assembly District.

Nguyen had beaten Kalra by nearly 15 percentage points in the June primary. But early returns Tuesday showed the two Democratic contenders in a dead heat. And as election results rolled in late Tuesday, Kalra not only narrowed Nguyen’s initial 130-vote lead, but surged ahead to surpass his opponent by nearly 4,000 votes Wednesday.

With tens of thousands of ballots yet to be counted, Nguyen wasn’t ready Wednesday to concede the race, though she said she called Kalra to congratulate him “on a race well run” and acknowledged she faces long odds.

“It will be very difficult for us to make up the difference,” Nguyen said in a statement. “But out of the respect for the nearly forty thousand votes that have yet to be counted, I am not going to make any announcements at this time.”

The two were competing to replace termed-out Assemblywoman Nora Campos.

In another local Assembly contest, Palo Alto City Councilmember Marc Berman held his lead over attorney Vicki Veenker for the 24th Assembly District. He was ahead 54 percent to 46 percent with a majority of ballots counted. He congratulated Veenker on Wednesday for “running a strong campaign.”

“I’m proud of the positive, issue-oriented campaign that we ran, and I’m incredibly grateful to the voters of the 24th Assembly District for the opportunity to be their next assemblymember,” said Berman.

Some political observers didn’t see Kalra’s win coming.

“I was surprised,” said Terry Christensen, a political science professor emeritus at San Jose State. “Given the margins she had in the primary election and the depths of her financial support through independent expenditures, I thought she’d win.”

Christensen said Nguyen could have lost support from her core constituency — Vietnamese voters — following a scandal involving naming an East San Jose shopping center. That political blunder led to a distrust from one faction of the Vietnamese community and a lawsuit against San Jose.

Or Nguyen’s supporters may have been overly confident.

Ben Field, executive officer of the South Bay AFL-CIO Labor Council, which backed Kalra, said it was important for organized labor to maintain Campos’ seat to represent East San Jose residents “who have been left behind in this economy.”

Kalra benefited from a higher voter turnout in Tuesday’s election which also drew a large population of Latino voters and younger voters. But the 44-year-old credits his success to a strong ground game — he says volunteers knocked on “tens of thousands” of doors.

“We worked harder than anyone could possibly imagine,” Kalra said Wednesday. “We really made an effort to reach out to folks who normally don’t vote and we convinced them it was an important enough election for them to show up to vote.”

Nguyen reported raising more than a $1 million and had nearly $5 million in independent expenditures supporting her and opposing her rival. Kalra raised half a million and had $2.4 million in independent expenditures supporting him and opposing Nguyen.

“But money does not replace enthusiasm, organization or commitment,” said Larry Gerston, a political science professor emeritus at San Jose State.